Vanessa 2025-12-01 18:51:58 +08:00
parent 0c6c90a82d
commit 12ebc120a0
10 changed files with 184 additions and 119 deletions

View file

@ -148,8 +148,14 @@ export const moveToPath = (fromPaths: string[], toNotebook: string, toPath: stri
});
};
export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
paths?: string[], range?: Range, title?: string, flashcard = false) => {
export const movePathTo = (options: {
cb: (toPath: string[], toNotebook: string[]) => void,
paths?: string[],
range?: Range,
title?: string,
flashcard: boolean
rootIDs?: string[],
}) => {
const exitDialog = window.siyuan.dialogs.find((item) => {
if (item.element.querySelector("#foldList")) {
item.destroy();
@ -161,7 +167,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
}
const dialog = new Dialog({
title: `<div style="padding: 8px;">
${title || window.siyuan.languages.move}
${options.title || window.siyuan.languages.move}
<div style="max-height: 16px;line-height: 14px;-webkit-mask-image: linear-gradient(to top, rgba(0, 0, 0, 0) 0, #000 6px);padding-bottom: 4px;margin-bottom: -4px" class="ft__smaller ft__on-surface fn__hidescrollbar"></div>
</div>`,
content: `<div class="b3-form__icon" style="margin: 8px">
@ -181,15 +187,15 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
width: isMobile() ? "92vw" : "50vw",
height: isMobile() ? "80vh" : "70vh",
destroyCallback() {
if (range) {
focusByRange(range);
if (options.range) {
focusByRange(options.range);
}
}
});
dialog.element.querySelector(".b3-dialog__header").setAttribute("style", "padding:0");
dialog.element.setAttribute("data-key", Constants.DIALOG_MOVEPATHTO);
if (paths && paths.length > 0) {
fetchPost("/api/filetree/getHPathsByPaths", {paths}, (response) => {
if (options.paths && options.paths.length > 0) {
fetchPost("/api/filetree/getHPathsByPaths", {paths: options.paths}, (response) => {
dialog.element.querySelector(".b3-dialog__header .ft__smaller").innerHTML = escapeHtml(response.data.join(" "));
});
}
@ -200,7 +206,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
notebooks.forEach((item) => {
if (!item.closed) {
let countHTML = "";
if (flashcard) {
if (options.flashcard) {
countHTML = `<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardNewCard}">${item.newFlashcardCount}</span>
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardDueCard}">${item.dueFlashcardCount}</span>
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardCard}">${item.flashcardCount}</span>`;
@ -217,7 +223,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
}
});
searchTreeElement.innerHTML = html;
}, flashcard);
}, options.flashcard);
const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement;
inputElement.value = window.siyuan.storage[Constants.LOCAL_MOVE_PATH].k;
@ -238,7 +244,8 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
searchListElement.scrollTo(0, 0);
fetchPost("/api/filetree/searchDocs", {
k: inputElement.value,
flashcard,
flashcard: options.flashcard,
excludeIDs: options.rootIDs,
}, (data) => {
let fileHTML = "";
data.data.forEach((item: {
@ -251,7 +258,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
flashcardCount: string
}) => {
let countHTML = "";
if (flashcard) {
if (options.flashcard) {
countHTML = `<span class="fn__flex-1"></span>
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardNewCard}">${item.newFlashcardCount}</span>
<span class="counter counter--right b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.flashcardDueCard}">${item.dueFlashcardCount}</span>
@ -383,7 +390,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
if (searchListElement.classList.contains("fn__none")) {
if ((event.key === "ArrowRight" && !currentItemElement.querySelector(".b3-list-item__arrow--open") && !currentItemElement.querySelector(".b3-list-item__toggle").classList.contains("fn__hidden")) ||
(event.key === "ArrowLeft" && currentItemElement.querySelector(".b3-list-item__arrow--open"))) {
getLeaf(currentItemElement, flashcard);
getLeaf(currentItemElement, options.flashcard);
event.preventDefault();
return;
}
@ -516,7 +523,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
pathList.push(item.getAttribute("data-path"));
notebookIdList.push(item.getAttribute("data-box"));
});
cb(pathList, notebookIdList);
options.cb(pathList, notebookIdList);
dialog.destroy();
event.preventDefault();
}
@ -525,7 +532,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(dialog.element)) {
if (target.classList.contains("b3-list-item__toggle")) {
getLeaf(target.parentElement, flashcard);
getLeaf(target.parentElement, options.flashcard);
event.preventDefault();
event.stopPropagation();
break;
@ -546,7 +553,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
pathList.push(item.getAttribute("data-path"));
notebookIdList.push(item.getAttribute("data-box"));
});
cb(pathList, notebookIdList);
options.cb(pathList, notebookIdList);
dialog.destroy();
event.preventDefault();
event.stopPropagation();
@ -562,7 +569,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
if (currentItemElements.length === 0) {
return;
}
if (title === window.siyuan.languages.specifyPath && isOnlyMeta(event)) {
if (options.title === window.siyuan.languages.specifyPath && isOnlyMeta(event)) {
if (currentItemElements.length === 1 && currentItemElements[0] === target) {
// 至少需选中一个
} else {
@ -573,7 +580,7 @@ export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void,
target.classList.add("b3-list-item--focus");
}
if (target.getAttribute("data-path") === "/") {
getLeaf(target, flashcard);
getLeaf(target, options.flashcard);
}
event.preventDefault();
event.stopPropagation();