From e735472600b8bf22d01899bb0831b6cc21690e2a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 21 Nov 2024 12:31:00 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13163 --- app/src/card/openCard.ts | 160 ++++++++++++++++++++++++--------------- 1 file changed, 98 insertions(+), 62 deletions(-) diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts index 57b6f6c5d..de723af3f 100644 --- a/app/src/card/openCard.ts +++ b/app/src/card/openCard.ts @@ -94,11 +94,7 @@ export const genCardHTML = (options: { /// #endif return `
${iconsHTML} -
+
🔮
${window.siyuan.languages.noDueCard} @@ -113,7 +109,7 @@ ${window.siyuan.config.flashcard.list ? "card__block--hideli" : ""}" data-type="
- ${window.siyuan.languages.nextRound} +
`; }; +const getEditor = (id: string, protyle: IProtyle, element: Element, currentCard: ICard) => { + fetchPost("/api/block/getDocInfo", { + id, + }, (response) => { + protyle.wysiwyg.renderCustom(response.data.ial); + fetchPost("/api/filetree/getDoc", { + id, + mode: 0, + size: Constants.SIZE_GET_MAX + }, (response) => { + onGet({ + updateReadonly: true, + data: response, + protyle, + action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], + afterCB: () => { + let hasHide = false; + if (!window.siyuan.config.flashcard.superBlock && + !window.siyuan.config.flashcard.heading && + !window.siyuan.config.flashcard.list && + !window.siyuan.config.flashcard.mark) { + hasHide = false; + } else { + if (window.siyuan.config.flashcard.superBlock) { + if (protyle.wysiwyg.element.querySelector(":scope > .sb")) { + hasHide = true; + } + } + if (window.siyuan.config.flashcard.heading) { + if (protyle.wysiwyg.element.querySelector(':scope > [data-type="NodeHeading"]')) { + hasHide = true; + } + } + if (window.siyuan.config.flashcard.list) { + if (protyle.wysiwyg.element.querySelector(".list, .li")) { + hasHide = true; + } + } + if (window.siyuan.config.flashcard.mark) { + if (protyle.wysiwyg.element.querySelector('span[data-type~="mark"]')) { + hasHide = true; + } + } + } + const actionElements = element.querySelectorAll(".card__action"); + if (!hasHide) { + protyle.element.classList.remove("card__block--hidemark", "card__block--hideli", "card__block--hidesb", "card__block--hideh"); + actionElements[0].classList.add("fn__none"); + actionElements[1].querySelectorAll("button.b3-button").forEach((element, btnIndex) => { + if (btnIndex < 2) { + return; + } + element.previousElementSibling.textContent = currentCard.nextDues[btnIndex-1]; + }); + actionElements[1].classList.remove("fn__none"); + } else { + if (window.siyuan.config.flashcard.superBlock) { + protyle.element.classList.add("card__block--hidesb"); + } + if (window.siyuan.config.flashcard.heading) { + protyle.element.classList.add("card__block--hideh"); + } + if (window.siyuan.config.flashcard.list) { + protyle.element.classList.add("card__block--hideli"); + } + if (window.siyuan.config.flashcard.mark) { + protyle.element.classList.add("card__block--hidemark"); + } + actionElements[0].classList.remove("fn__none"); + actionElements[1].classList.add("fn__none"); + } + } + }); + }); + }); + +} + export const bindCardEvent = async (options: { app: App, element: Element, @@ -183,30 +257,16 @@ export const bindCardEvent = async (options: { window.siyuan.mobile.popEditor = editor; } if (options.cardsData.cards.length > 0) { - fetchPost("/api/block/getDocInfo", { - id: options.cardsData.cards[index].blockID, - }, (response) => { - editor.protyle.wysiwyg.renderCustom(response.data.ial); - fetchPost("/api/filetree/getDoc", { - id: options.cardsData.cards[index].blockID, - mode: 0, - size: Constants.SIZE_GET_MAX - }, (response) => { - onGet({ - updateReadonly: true, - data: response, - protyle: editor.protyle, - action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], - }); - }); - }); + getEditor(options.cardsData.cards[index].blockID, editor.protyle, options.element, options.cardsData.cards[index]); } options.element.setAttribute("data-key", Constants.DIALOG_OPENCARD); const actionElements = options.element.querySelectorAll(".card__action"); if (options.index === 0 || typeof options.index === "undefined") { actionElements[0].firstElementChild.setAttribute("disabled", "disabled"); + actionElements[1].querySelector(".b3-button").setAttribute("disabled", "disabled"); } else { actionElements[0].firstElementChild.removeAttribute("disabled"); + actionElements[1].querySelector(".b3-button").removeAttribute("disabled"); } const countElement = options.element.querySelector('[data-type="count"]'); const filterElement = options.element.querySelector('[data-type="filter"]'); @@ -352,8 +412,11 @@ export const bindCardEvent = async (options: { 3: minLang.replace("1", "10"), 4: window.siyuan.languages._time["1d"].replace("%s", "").replace("1", "6") }; - actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => { - element.previousElementSibling.textContent = currentCard.nextDues[btnIndex]; + actionElements[1].querySelectorAll("button.b3-button").forEach((element, btnIndex) => { + if (btnIndex < 2) { + return; + } + element.previousElementSibling.textContent = currentCard.nextDues[btnIndex-1]; }); options.cardsData.unreviewedOldCardCount--; options.cardsData.unreviewedNewCardCount++; @@ -575,17 +638,17 @@ export const bindCardEvent = async (options: { } else { editor.protyle.element.classList.remove("card__block--hidemark", "card__block--hideli", "card__block--hidesb", "card__block--hideh"); actionElements[0].classList.add("fn__none"); - actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => { - element.previousElementSibling.textContent = currentCard.nextDues[btnIndex]; + actionElements[1].querySelectorAll("button.b3-button").forEach((element, btnIndex) => { + if (btnIndex < 2) { + return; + } + element.previousElementSibling.textContent = currentCard.nextDues[btnIndex-1]; }); actionElements[1].classList.remove("fn__none"); emitEvent(options.app, currentCard, type); return; } } else if (type === "-2") { // 上一步 - if (actionElements[0].classList.contains("fn__none")) { - return; - } if (index > 0) { index--; nextCard({ @@ -752,47 +815,20 @@ const nextCard = (options: { index: number, cardsData: ICardData }) => { - options.editor.protyle.element.classList.add("card__block--hide"); - if (window.siyuan.config.flashcard.superBlock) { - options.editor.protyle.element.classList.add("card__block--hidesb"); - } - if (window.siyuan.config.flashcard.heading) { - options.editor.protyle.element.classList.add("card__block--hideh"); - } - if (window.siyuan.config.flashcard.list) { - options.editor.protyle.element.classList.add("card__block--hideli"); - } - if (window.siyuan.config.flashcard.mark) { - options.editor.protyle.element.classList.add("card__block--hidemark"); - } - options.actionElements[0].classList.remove("fn__none"); - options.actionElements[1].classList.add("fn__none"); options.editor.protyle.element.classList.remove("fn__none"); options.editor.protyle.element.nextElementSibling.classList.add("fn__none"); options.countElement.innerHTML = genCardCount(options.cardsData, options.index); options.countElement.classList.remove("fn__none"); if (options.index === 0) { options.actionElements[0].firstElementChild.setAttribute("disabled", "disabled"); + options.actionElements[1].querySelector(".b3-button").setAttribute("disabled", "disabled"); } else { options.actionElements[0].firstElementChild.removeAttribute("disabled"); + options.actionElements[1].querySelector(".b3-button").removeAttribute("disabled"); } - fetchPost("/api/block/getDocInfo", { - id: options.cardsData.cards[options.index].blockID, - }, (response) => { - options.editor.protyle.wysiwyg.renderCustom(response.data.ial); - fetchPost("/api/filetree/getDoc", { - id: options.cardsData.cards[options.index].blockID, - mode: 0, - size: Constants.SIZE_GET_MAX - }, (response) => { - onGet({ - updateReadonly: true, - data: response, - protyle: options.editor.protyle, - action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML], - }); - }); - }); + getEditor(options.cardsData.cards[options.index].blockID, options.editor.protyle, + hasClosestByAttribute(options.countElement, "data-key", Constants.DIALOG_OPENCARD) as HTMLElement, + options.cardsData.cards[options.index]); }; const allDone = (countElement: Element, editor: Protyle, actionElements: NodeListOf) => {