Vanessa 2024-11-21 12:31:00 +08:00
parent 0e357f7311
commit e735472600

View file

@ -94,11 +94,7 @@ export const genCardHTML = (options: {
/// #endif
return `<div class="card__main">
${iconsHTML}
<div class="card__block fn__flex-1 ${options.cardsData.cards.length === 0 ? "fn__none" : ""}
${window.siyuan.config.flashcard.mark ? "card__block--hidemark" : ""}
${window.siyuan.config.flashcard.superBlock ? "card__block--hidesb" : ""}
${window.siyuan.config.flashcard.heading ? "card__block--hideh" : ""}
${window.siyuan.config.flashcard.list ? "card__block--hideli" : ""}" data-type="render"></div>
<div class="card__block fn__flex-1 ${options.cardsData.cards.length === 0 ? "fn__none" : ""}" data-type="render"></div>
<div class="card__empty card__empty--space${options.cardsData.cards.length === 0 ? "" : " fn__none"}" data-type="empty">
<div>🔮</div>
${window.siyuan.languages.noDueCard}
@ -113,7 +109,7 @@ ${window.siyuan.config.flashcard.list ? "card__block--hideli" : ""}" data-type="
</div>
<div class="fn__flex card__action fn__none">
<div>
<span>${window.siyuan.languages.nextRound}</span>
<button class="b3-button b3-button--cancel" disabled="disabled" style="display: flex;margin-bottom: 8px;height: 28px;padding: 0;" data-type="-2"><svg><use xlink:href="#iconLeft"></use></svg>(p / q)</button>
<button data-type="-3" aria-label="0 / x" class="b3-button b3-button--cancel b3-tooltips__n b3-tooltips">
<div class="card__icon">💤</div>
${window.siyuan.languages.skip} (0)
@ -151,6 +147,84 @@ ${window.siyuan.config.flashcard.list ? "card__block--hideli" : ""}" data-type="
</div>`;
};
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<Element>) => {