2022-12-22 14:52:43 +08:00
|
|
|
import {Dialog} from "../dialog";
|
|
|
|
|
import {fetchPost} from "../util/fetch";
|
|
|
|
|
import {isMobile} from "../util/functions";
|
2022-12-22 15:37:21 +08:00
|
|
|
import {Protyle} from "../protyle";
|
|
|
|
|
import {Constants} from "../constants";
|
2023-09-12 10:22:04 +08:00
|
|
|
import {onGet} from "../protyle/util/onGet";
|
2023-04-03 19:50:25 +08:00
|
|
|
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
2023-02-19 09:55:34 +08:00
|
|
|
import {hideElements} from "../protyle/ui/hideElements";
|
2023-07-21 17:20:34 +08:00
|
|
|
import {needLogin, needSubscribe} from "../util/needSubscribe";
|
2023-04-03 19:50:25 +08:00
|
|
|
import {fullscreen} from "../protyle/breadcrumb/action";
|
2023-04-14 12:03:11 +08:00
|
|
|
import {MenuItem} from "../menus/Menu";
|
|
|
|
|
import {escapeHtml} from "../util/escape";
|
2023-04-28 16:01:02 +08:00
|
|
|
/// #if !MOBILE
|
2023-04-28 22:08:57 +08:00
|
|
|
import {openFile} from "../editor/util";
|
2023-04-28 16:01:02 +08:00
|
|
|
/// #endif
|
|
|
|
|
import {getDisplayName, movePathTo} from "../util/pathName";
|
2023-05-18 19:27:21 +08:00
|
|
|
import {App} from "../index";
|
2023-09-14 09:56:13 +08:00
|
|
|
import {resize} from "../protyle/util/resize";
|
2023-10-23 11:35:44 +08:00
|
|
|
import {setStorageVal} from "../protyle/util/compatibility";
|
2022-12-22 14:52:43 +08:00
|
|
|
|
2023-12-22 10:25:55 +08:00
|
|
|
const genCardCount = (unreviewedNewCardCount: number, unreviewedOldCardCount: number,) => {
|
2023-12-22 10:54:47 +08:00
|
|
|
return `<span class="ft__error">1</span>
|
|
|
|
|
<span class="fn__space"></span>/<span class="fn__space"></span>
|
|
|
|
|
<span class="ariaLabel ft__primary" aria-label="${window.siyuan.languages.flashcardNewCard}">${unreviewedNewCardCount}</span>
|
|
|
|
|
<span class="fn__space"></span>+<span class="fn__space"></span>
|
|
|
|
|
<span class="ariaLabel ft__success" aria-label="${window.siyuan.languages.flashcardReviewCard}">${unreviewedOldCardCount}</span>`;
|
2023-12-22 10:25:55 +08:00
|
|
|
}
|
|
|
|
|
|
2023-04-27 20:03:00 +08:00
|
|
|
export const genCardHTML = (options: {
|
|
|
|
|
id: string,
|
|
|
|
|
cardType: TCardType,
|
2023-12-22 10:25:55 +08:00
|
|
|
cardsData: {
|
|
|
|
|
cards: ICard[],
|
|
|
|
|
unreviewedCount: number
|
|
|
|
|
unreviewedNewCardCount: number
|
|
|
|
|
unreviewedOldCardCount: number
|
|
|
|
|
},
|
2023-04-27 20:03:00 +08:00
|
|
|
isTab: boolean
|
|
|
|
|
}) => {
|
2023-05-10 00:01:47 +08:00
|
|
|
let iconsHTML: string;
|
2023-04-28 16:01:02 +08:00
|
|
|
/// #if MOBILE
|
2023-05-10 00:01:47 +08:00
|
|
|
iconsHTML = `<div class="toolbar toolbar--border">
|
2023-04-28 16:01:02 +08:00
|
|
|
<svg class="toolbar__icon"><use xlink:href="#iconRiffCard"></use></svg>
|
|
|
|
|
<span class="fn__flex-1 fn__flex-center toolbar__text">${window.siyuan.languages.riffCard}</span>
|
2023-12-22 10:54:47 +08:00
|
|
|
<div data-type="count" class="${options.cardsData.unreviewedCount === 0 ? "fn__none" : "fn__flex"}">${genCardCount(options.cardsData.unreviewedNewCardCount, options.cardsData.unreviewedOldCardCount)}</span></div>
|
2023-04-28 16:01:02 +08:00
|
|
|
<svg class="toolbar__icon" data-id="${options.id || ""}" data-cardtype="${options.cardType}" data-type="filter"><use xlink:href="#iconFilter"></use></svg>
|
|
|
|
|
<svg class="toolbar__icon" data-type="close"><use xlink:href="#iconCloseRound"></use></svg>
|
|
|
|
|
</div>`;
|
|
|
|
|
/// #else
|
2023-05-10 00:01:47 +08:00
|
|
|
iconsHTML = `<div class="block__icons">
|
2023-04-28 16:01:02 +08:00
|
|
|
${options.isTab ? '<div class="fn__flex-1"></div>' : `<div class="block__icon block__icon--show">
|
|
|
|
|
<svg><use xlink:href="#iconRiffCard"></use></svg>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
2023-11-13 09:31:57 +08:00
|
|
|
<span class="fn__flex-center">${window.siyuan.languages.riffCard}</span>`}
|
|
|
|
|
<span class="fn__space fn__flex-1 resize__move" style="min-height: 100%"></span>
|
2023-12-22 10:54:47 +08:00
|
|
|
<div data-type="count" class="ft__on-surface ft__smaller fn__flex-center${options.cardsData.unreviewedCount === 0 ? " fn__none" : " fn__flex"}">${genCardCount(options.cardsData.unreviewedNewCardCount, options.cardsData.unreviewedOldCardCount)}</span></div>
|
2023-04-14 12:03:11 +08:00
|
|
|
<div class="fn__space"></div>
|
2023-04-27 20:03:00 +08:00
|
|
|
<div data-id="${options.id || ""}" data-cardtype="${options.cardType}" data-type="filter" class="block__icon block__icon--show">
|
2023-04-14 12:03:11 +08:00
|
|
|
<svg><use xlink:href="#iconFilter"></use></svg>
|
|
|
|
|
</div>
|
2023-04-08 22:02:47 +08:00
|
|
|
<div class="fn__space"></div>
|
2023-04-28 16:01:02 +08:00
|
|
|
<div data-type="fullscreen" class="b3-tooltips b3-tooltips__sw block__icon block__icon--show" aria-label="${window.siyuan.languages.fullscreen}">
|
|
|
|
|
<svg><use xlink:href="#iconFullscreen"></use></svg>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="fn__space${options.isTab ? " fn__none" : ""}"></div>
|
|
|
|
|
<div data-type="sticktab" class="b3-tooltips b3-tooltips__sw block__icon block__icon--show${options.isTab ? " fn__none" : ""}" aria-label="${window.siyuan.languages.openInNewTab}">
|
|
|
|
|
<svg><use xlink:href="#iconLayoutRight"></use></svg>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
/// #endif
|
|
|
|
|
return `<div class="card__main">
|
|
|
|
|
${iconsHTML}
|
2023-12-22 10:25:55 +08:00
|
|
|
<div class="card__block fn__flex-1 ${options.cardsData.unreviewedCount === 0 ? "fn__none" : ""}
|
2023-10-04 11:32:25 +08:00
|
|
|
${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>
|
2023-12-22 10:25:55 +08:00
|
|
|
<div class="card__empty card__empty--space${options.cardsData.unreviewedCount === 0 ? "" : " fn__none"}" data-type="empty">
|
2023-02-19 00:20:18 +08:00
|
|
|
<div>🔮</div>
|
2023-02-19 00:05:38 +08:00
|
|
|
${window.siyuan.languages.noDueCard}
|
|
|
|
|
</div>
|
2023-12-22 10:25:55 +08:00
|
|
|
<div class="fn__flex card__action${options.cardsData.unreviewedCount === 0 ? " fn__none" : ""}">
|
2023-02-26 11:34:30 +08:00
|
|
|
<button class="b3-button b3-button--cancel" disabled="disabled" data-type="-2" style="width: 25%;min-width: 86px;display: flex">
|
|
|
|
|
<svg><use xlink:href="#iconLeft"></use></svg>
|
|
|
|
|
(p)
|
|
|
|
|
</button>
|
|
|
|
|
<span class="fn__space"></span>
|
2023-12-15 09:25:52 +08:00
|
|
|
<button data-type="-1" class="b3-button fn__flex-1">${window.siyuan.languages.cardShowAnswer} (${window.siyuan.languages.space} / Enter)</button>
|
2022-12-29 11:50:06 +08:00
|
|
|
</div>
|
2023-02-24 10:01:40 +08:00
|
|
|
<div class="fn__flex card__action fn__none">
|
2023-03-19 14:50:08 +08:00
|
|
|
<div>
|
2023-04-13 10:16:09 +08:00
|
|
|
<span>${window.siyuan.languages.nextRound}</span>
|
2023-04-28 10:30:27 +08:00
|
|
|
<button data-type="-3" aria-label="0" class="b3-button b3-button--cancel b3-tooltips__n b3-tooltips">
|
2023-03-19 14:50:08 +08:00
|
|
|
<div>💤</div>
|
|
|
|
|
${window.siyuan.languages.skip} (0)
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2022-12-29 15:30:10 +08:00
|
|
|
<div>
|
2022-12-29 15:44:57 +08:00
|
|
|
<span></span>
|
2023-08-01 18:21:00 +08:00
|
|
|
<button data-type="1" aria-label="1 / j" class="b3-button b3-button--error b3-tooltips__n b3-tooltips">
|
2023-02-24 20:43:06 +08:00
|
|
|
<div>🙈</div>
|
2023-02-24 13:38:32 +08:00
|
|
|
${window.siyuan.languages.cardRatingAgain} (1)
|
2023-02-24 09:32:39 +08:00
|
|
|
</button>
|
2022-12-29 15:30:10 +08:00
|
|
|
</div>
|
|
|
|
|
<div>
|
2022-12-29 15:44:57 +08:00
|
|
|
<span></span>
|
2023-08-01 18:21:00 +08:00
|
|
|
<button data-type="2" aria-label="2 / k" class="b3-button b3-button--warning b3-tooltips__n b3-tooltips">
|
2023-02-24 10:33:04 +08:00
|
|
|
<div>😬</div>
|
2023-02-24 13:38:32 +08:00
|
|
|
${window.siyuan.languages.cardRatingHard} (2)
|
2023-02-24 10:33:04 +08:00
|
|
|
</button>
|
2022-12-29 15:30:10 +08:00
|
|
|
</div>
|
|
|
|
|
<div>
|
2022-12-29 15:44:57 +08:00
|
|
|
<span></span>
|
2023-12-15 09:25:52 +08:00
|
|
|
<button data-type="3" aria-label="3 / l / ${window.siyuan.languages.space} / Enter" class="b3-button b3-button--info b3-tooltips__n b3-tooltips">
|
2023-02-24 10:33:04 +08:00
|
|
|
<div>😊</div>
|
2023-02-24 13:38:32 +08:00
|
|
|
${window.siyuan.languages.cardRatingGood} (3)
|
2023-02-24 10:33:04 +08:00
|
|
|
</button>
|
2022-12-29 15:30:10 +08:00
|
|
|
</div>
|
|
|
|
|
<div>
|
2022-12-29 15:44:57 +08:00
|
|
|
<span></span>
|
2023-08-01 18:21:00 +08:00
|
|
|
<button data-type="4" aria-label="4 / ;" class="b3-button b3-button--success b3-tooltips__n b3-tooltips">
|
2023-02-24 10:33:04 +08:00
|
|
|
<div>🌈</div>
|
2023-02-24 13:38:32 +08:00
|
|
|
${window.siyuan.languages.cardRatingEasy} (4)
|
2023-02-24 10:33:04 +08:00
|
|
|
</button>
|
2022-12-29 15:30:10 +08:00
|
|
|
</div>
|
2022-12-22 14:52:43 +08:00
|
|
|
</div>
|
2023-04-27 20:03:00 +08:00
|
|
|
</div>`;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-28 10:30:27 +08:00
|
|
|
export const bindCardEvent = (options: {
|
2023-05-18 19:27:21 +08:00
|
|
|
app: App,
|
2023-04-28 10:30:27 +08:00
|
|
|
element: Element,
|
|
|
|
|
title?: string,
|
2023-12-22 10:25:55 +08:00
|
|
|
cardsData: {
|
|
|
|
|
cards: ICard[],
|
|
|
|
|
unreviewedCount: number
|
|
|
|
|
unreviewedNewCardCount: number
|
|
|
|
|
unreviewedOldCardCount: number
|
|
|
|
|
}
|
2023-04-28 10:30:27 +08:00
|
|
|
cardType: TCardType,
|
|
|
|
|
id?: string,
|
2023-04-28 12:02:08 +08:00
|
|
|
dialog?: Dialog,
|
2023-10-31 20:03:42 +08:00
|
|
|
index?: number
|
2023-04-28 10:30:27 +08:00
|
|
|
}) => {
|
2023-10-23 11:35:44 +08:00
|
|
|
if (window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen) {
|
|
|
|
|
fullscreen(options.element.querySelector(".card__main"),
|
|
|
|
|
options.element.querySelector('[data-type="fullscreen"]'));
|
|
|
|
|
}
|
2023-04-27 20:03:00 +08:00
|
|
|
let index = 0;
|
2023-10-31 20:03:42 +08:00
|
|
|
if (typeof options.index === "number") {
|
2023-11-02 11:20:47 +08:00
|
|
|
index = options.index;
|
2023-10-31 20:03:42 +08:00
|
|
|
}
|
2023-05-18 19:27:21 +08:00
|
|
|
const editor = new Protyle(options.app, options.element.querySelector("[data-type='render']") as HTMLElement, {
|
2023-02-19 00:05:38 +08:00
|
|
|
blockId: "",
|
|
|
|
|
action: [Constants.CB_GET_ALL],
|
|
|
|
|
render: {
|
|
|
|
|
background: false,
|
|
|
|
|
title: false,
|
|
|
|
|
gutter: true,
|
|
|
|
|
breadcrumbDocName: true,
|
|
|
|
|
},
|
|
|
|
|
typewriterMode: false
|
|
|
|
|
});
|
2023-04-12 14:46:17 +08:00
|
|
|
if (window.siyuan.mobile) {
|
|
|
|
|
window.siyuan.mobile.popEditor = editor;
|
|
|
|
|
}
|
2023-12-22 10:25:55 +08:00
|
|
|
if (options.cardsData.unreviewedCount > 0) {
|
2023-02-19 00:05:38 +08:00
|
|
|
fetchPost("/api/filetree/getDoc", {
|
2023-12-22 10:25:55 +08:00
|
|
|
id: options.cardsData.cards[index].blockID,
|
2023-02-19 00:05:38 +08:00
|
|
|
mode: 0,
|
|
|
|
|
size: Constants.SIZE_GET_MAX
|
|
|
|
|
}, (response) => {
|
2023-06-01 14:56:21 +08:00
|
|
|
onGet({
|
|
|
|
|
data: response,
|
|
|
|
|
protyle: editor.protyle,
|
2023-10-01 10:49:52 +08:00
|
|
|
action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
2023-06-01 14:56:21 +08:00
|
|
|
});
|
2023-02-19 00:05:38 +08:00
|
|
|
});
|
|
|
|
|
}
|
2023-12-22 12:30:12 +08:00
|
|
|
options.element.setAttribute("data-key", Constants.DIALOG_OPENCARD);
|
2023-12-22 10:25:55 +08:00
|
|
|
const countElement = options.element.querySelector('[data-type="count"] span');
|
|
|
|
|
countElement.innerHTML = (index + 1).toString();
|
2023-04-28 10:30:27 +08:00
|
|
|
const actionElements = options.element.querySelectorAll(".card__action");
|
2023-12-22 11:30:51 +08:00
|
|
|
if (options.index === 0) {
|
|
|
|
|
actionElements[0].firstElementChild.setAttribute("disabled", "disabled");
|
|
|
|
|
} else {
|
|
|
|
|
actionElements[0].firstElementChild.removeAttribute("disabled");
|
|
|
|
|
}
|
2023-04-28 10:30:27 +08:00
|
|
|
const filterElement = options.element.querySelector('[data-type="filter"]');
|
2023-04-14 12:03:11 +08:00
|
|
|
const fetchNewRound = () => {
|
2023-04-14 22:42:21 +08:00
|
|
|
const currentCardType = filterElement.getAttribute("data-cardtype");
|
2023-04-14 12:03:11 +08:00
|
|
|
fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" :
|
|
|
|
|
(currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
|
|
|
|
|
rootID: filterElement.getAttribute("data-id"),
|
|
|
|
|
deckID: filterElement.getAttribute("data-id"),
|
|
|
|
|
notebook: filterElement.getAttribute("data-id"),
|
|
|
|
|
}, (treeCards) => {
|
|
|
|
|
index = 0;
|
2023-12-25 00:34:16 +08:00
|
|
|
options.cardsData = treeCards.data;
|
2023-12-22 10:25:55 +08:00
|
|
|
if (options.cardsData.unreviewedCount > 0) {
|
2023-04-14 12:03:11 +08:00
|
|
|
nextCard({
|
|
|
|
|
countElement,
|
|
|
|
|
editor,
|
|
|
|
|
actionElements,
|
|
|
|
|
index,
|
2023-12-22 10:25:55 +08:00
|
|
|
blocks: options.cardsData.cards
|
2023-04-14 12:03:11 +08:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
allDone(countElement, editor, actionElements);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-04-14 22:42:21 +08:00
|
|
|
};
|
2023-04-14 12:03:11 +08:00
|
|
|
|
2023-04-28 10:30:27 +08:00
|
|
|
options.element.addEventListener("click", (event: MouseEvent) => {
|
2023-04-12 09:26:19 +08:00
|
|
|
const target = event.target as HTMLElement;
|
2023-02-19 00:05:38 +08:00
|
|
|
let type = "";
|
|
|
|
|
if (typeof event.detail === "string") {
|
2023-02-23 18:57:04 +08:00
|
|
|
if (event.detail === "1" || event.detail === "j") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "1";
|
2023-08-01 18:21:00 +08:00
|
|
|
} else if (event.detail === "2" || event.detail === "k") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "2";
|
2023-08-01 18:21:00 +08:00
|
|
|
} else if (event.detail === "3" || event.detail === "l") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "3";
|
2023-08-01 18:21:00 +08:00
|
|
|
} else if (event.detail === "4" || event.detail === ";") {
|
|
|
|
|
type = "4";
|
2023-12-15 09:25:52 +08:00
|
|
|
} else if (event.detail === " " || event.detail === "enter") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "-1";
|
2023-02-26 11:45:50 +08:00
|
|
|
} else if (event.detail === "p") {
|
2023-02-26 11:34:30 +08:00
|
|
|
type = "-2";
|
2023-03-19 14:50:08 +08:00
|
|
|
} else if (event.detail === "0") {
|
|
|
|
|
type = "-3";
|
2023-02-19 00:05:38 +08:00
|
|
|
}
|
2023-04-12 09:26:19 +08:00
|
|
|
} else {
|
|
|
|
|
const fullscreenElement = hasClosestByAttribute(target, "data-type", "fullscreen");
|
|
|
|
|
if (fullscreenElement) {
|
2023-04-28 10:30:27 +08:00
|
|
|
fullscreen(options.element.querySelector(".card__main"),
|
|
|
|
|
options.element.querySelector('[data-type="fullscreen"]'));
|
2023-09-14 09:56:13 +08:00
|
|
|
resize(editor.protyle);
|
2023-10-24 10:42:04 +08:00
|
|
|
window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen = !window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen;
|
2023-10-31 20:03:42 +08:00
|
|
|
setStorageVal(Constants.LOCAL_FLASHCARD, window.siyuan.storage[Constants.LOCAL_FLASHCARD]);
|
2023-04-12 09:26:19 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-28 16:01:02 +08:00
|
|
|
/// #if !MOBILE
|
2023-04-27 20:03:00 +08:00
|
|
|
const sticktabElement = hasClosestByAttribute(target, "data-type", "sticktab");
|
|
|
|
|
if (sticktabElement) {
|
2023-04-28 22:08:57 +08:00
|
|
|
openFile({
|
2023-05-18 19:27:21 +08:00
|
|
|
app: options.app,
|
2023-04-28 22:08:57 +08:00
|
|
|
position: "right",
|
2023-05-10 00:01:47 +08:00
|
|
|
custom: {
|
|
|
|
|
icon: "iconRiffCard",
|
|
|
|
|
title: window.siyuan.languages.spaceRepetition,
|
|
|
|
|
data: {
|
2023-12-22 11:30:51 +08:00
|
|
|
cardsData: options.cardsData,
|
2023-10-31 20:03:42 +08:00
|
|
|
index,
|
2023-05-10 00:01:47 +08:00
|
|
|
cardType: filterElement.getAttribute("data-cardtype") as TCardType,
|
|
|
|
|
id: filterElement.getAttribute("data-id"),
|
|
|
|
|
title: options.title
|
|
|
|
|
},
|
2023-08-18 17:38:11 +08:00
|
|
|
id: "siyuan-card"
|
2023-05-10 00:01:47 +08:00
|
|
|
},
|
2023-04-27 20:03:00 +08:00
|
|
|
});
|
2023-04-28 12:02:08 +08:00
|
|
|
if (options.dialog) {
|
|
|
|
|
options.dialog.destroy();
|
|
|
|
|
}
|
2023-04-27 20:03:00 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-28 16:01:02 +08:00
|
|
|
/// #endif
|
2023-04-12 09:26:19 +08:00
|
|
|
const closeElement = hasClosestByAttribute(target, "data-type", "close");
|
|
|
|
|
if (closeElement) {
|
2023-04-28 12:02:08 +08:00
|
|
|
if (options.dialog) {
|
|
|
|
|
options.dialog.destroy();
|
|
|
|
|
}
|
2023-04-12 09:26:19 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-14 12:03:11 +08:00
|
|
|
const filterTempElement = hasClosestByAttribute(target, "data-type", "filter");
|
|
|
|
|
if (filterTempElement) {
|
|
|
|
|
fetchPost("/api/riff/getRiffDecks", {}, (response) => {
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
iconHTML: Constants.ZWSP,
|
|
|
|
|
label: window.siyuan.languages.all,
|
|
|
|
|
click() {
|
2023-04-14 22:42:21 +08:00
|
|
|
filterElement.setAttribute("data-id", "");
|
|
|
|
|
filterElement.setAttribute("data-cardtype", "all");
|
|
|
|
|
fetchNewRound();
|
2023-04-14 12:03:11 +08:00
|
|
|
},
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
iconHTML: Constants.ZWSP,
|
|
|
|
|
label: window.siyuan.languages.fileTree,
|
|
|
|
|
click() {
|
|
|
|
|
movePathTo((toPath, toNotebook) => {
|
2023-04-14 22:42:21 +08:00
|
|
|
filterElement.setAttribute("data-id", toPath[0] === "/" ? toNotebook[0] : getDisplayName(toPath[0], true, true));
|
|
|
|
|
filterElement.setAttribute("data-cardtype", toPath[0] === "/" ? "notebook" : "doc");
|
2023-04-14 12:03:11 +08:00
|
|
|
fetchNewRound();
|
2023-04-14 22:42:21 +08:00
|
|
|
}, [], undefined, window.siyuan.languages.specifyPath, true);
|
2023-04-14 12:03:11 +08:00
|
|
|
}
|
|
|
|
|
}).element);
|
2023-04-28 10:30:27 +08:00
|
|
|
if (options.title || response.data.length > 0) {
|
2023-04-17 12:48:53 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
}
|
2023-04-28 10:30:27 +08:00
|
|
|
if (options.title) {
|
2023-04-14 12:03:11 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
iconHTML: Constants.ZWSP,
|
2023-04-28 10:30:27 +08:00
|
|
|
label: escapeHtml(options.title),
|
2023-04-14 12:03:11 +08:00
|
|
|
click() {
|
2023-04-28 10:30:27 +08:00
|
|
|
filterElement.setAttribute("data-id", options.id);
|
|
|
|
|
filterElement.setAttribute("data-cardtype", options.cardType);
|
2023-04-14 22:42:21 +08:00
|
|
|
fetchNewRound();
|
2023-04-14 12:03:11 +08:00
|
|
|
},
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
}
|
|
|
|
|
response.data.forEach((deck: { id: string, name: string }) => {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
iconHTML: Constants.ZWSP,
|
|
|
|
|
label: escapeHtml(deck.name),
|
|
|
|
|
click() {
|
2023-04-14 22:42:21 +08:00
|
|
|
filterElement.setAttribute("data-id", deck.id);
|
|
|
|
|
filterElement.setAttribute("data-cardtype", "all");
|
|
|
|
|
fetchNewRound();
|
2023-04-14 12:03:11 +08:00
|
|
|
},
|
|
|
|
|
}).element);
|
2023-04-12 09:26:19 +08:00
|
|
|
});
|
2023-04-14 22:42:21 +08:00
|
|
|
const filterRect = filterTempElement.getBoundingClientRect();
|
2023-04-14 12:03:11 +08:00
|
|
|
window.siyuan.menus.menu.popup({x: filterRect.left, y: filterRect.bottom});
|
2023-04-12 14:48:01 +08:00
|
|
|
});
|
2023-04-12 09:26:19 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-14 12:03:11 +08:00
|
|
|
|
|
|
|
|
const newroundElement = hasClosestByAttribute(target, "data-type", "newround");
|
|
|
|
|
if (newroundElement) {
|
|
|
|
|
fetchNewRound();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-19 00:05:38 +08:00
|
|
|
}
|
|
|
|
|
if (!type) {
|
2023-04-12 09:26:19 +08:00
|
|
|
const buttonElement = hasClosestByClassName(target, "b3-button");
|
2023-02-19 00:05:38 +08:00
|
|
|
if (buttonElement) {
|
|
|
|
|
type = buttonElement.getAttribute("data-type");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-22 10:25:55 +08:00
|
|
|
if (!type || !options.cardsData.cards[index]) {
|
2023-02-19 00:05:38 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2023-12-22 11:30:51 +08:00
|
|
|
hideElements(["toolbar", "hint", "util", "gutter"], editor.protyle);
|
2023-03-24 20:54:02 +08:00
|
|
|
if (type === "-1") { // 显示答案
|
2023-02-26 11:45:50 +08:00
|
|
|
if (actionElements[0].classList.contains("fn__none")) {
|
2023-12-17 16:24:11 +08:00
|
|
|
type = "3";
|
2023-12-15 09:25:52 +08:00
|
|
|
} 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) => {
|
2023-12-22 10:25:55 +08:00
|
|
|
element.previousElementSibling.textContent = options.cardsData.cards[index].nextDues[btnIndex];
|
2023-12-15 09:25:52 +08:00
|
|
|
});
|
|
|
|
|
actionElements[1].classList.remove("fn__none");
|
2023-02-26 11:45:50 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-12-15 09:25:52 +08:00
|
|
|
} else if (type === "-2") { // 上一步
|
2023-02-26 11:45:50 +08:00
|
|
|
if (actionElements[0].classList.contains("fn__none")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-26 11:34:30 +08:00
|
|
|
if (index > 0) {
|
|
|
|
|
index--;
|
|
|
|
|
nextCard({
|
|
|
|
|
countElement,
|
|
|
|
|
editor,
|
|
|
|
|
actionElements,
|
|
|
|
|
index,
|
2023-12-22 10:25:55 +08:00
|
|
|
blocks: options.cardsData.cards
|
2023-02-26 11:45:50 +08:00
|
|
|
});
|
2023-02-26 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-28 18:52:45 +08:00
|
|
|
if (["1", "2", "3", "4", "-3"].includes(type) && actionElements[0].classList.contains("fn__none")) {
|
2023-03-19 14:50:08 +08:00
|
|
|
fetchPost(type === "-3" ? "/api/riff/skipReviewRiffCard" : "/api/riff/reviewRiffCard", {
|
2023-12-22 10:25:55 +08:00
|
|
|
deckID: options.cardsData.cards[index].deckID,
|
|
|
|
|
cardID: options.cardsData.cards[index].cardID,
|
2023-03-22 14:32:29 +08:00
|
|
|
rating: parseInt(type),
|
2023-12-22 10:25:55 +08:00
|
|
|
reviewedCards: options.cardsData.cards
|
2023-02-19 00:05:38 +08:00
|
|
|
}, () => {
|
2023-03-08 22:39:09 +08:00
|
|
|
/// #if MOBILE
|
2023-03-19 14:50:08 +08:00
|
|
|
if (type !== "-3" &&
|
2023-07-21 17:20:34 +08:00
|
|
|
((0 !== window.siyuan.config.sync.provider && !needLogin("")) ||
|
|
|
|
|
(0 === window.siyuan.config.sync.provider && !needSubscribe(""))) &&
|
2023-03-08 22:39:09 +08:00
|
|
|
window.siyuan.config.repo.key && window.siyuan.config.sync.enabled) {
|
|
|
|
|
document.getElementById("toolbarSync").classList.remove("fn__none");
|
|
|
|
|
}
|
|
|
|
|
/// #endif
|
2023-02-19 00:05:38 +08:00
|
|
|
index++;
|
2023-12-22 10:25:55 +08:00
|
|
|
if (index > options.cardsData.unreviewedCount - 1) {
|
2023-04-14 22:42:21 +08:00
|
|
|
const currentCardType = filterElement.getAttribute("data-cardtype");
|
2023-04-14 12:03:11 +08:00
|
|
|
fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" :
|
|
|
|
|
(currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
|
|
|
|
|
rootID: filterElement.getAttribute("data-id"),
|
|
|
|
|
deckID: filterElement.getAttribute("data-id"),
|
|
|
|
|
notebook: filterElement.getAttribute("data-id"),
|
2023-12-22 10:25:55 +08:00
|
|
|
reviewedCards: options.cardsData.cards
|
2023-04-12 10:01:08 +08:00
|
|
|
}, (result) => {
|
2023-02-26 11:45:50 +08:00
|
|
|
index = 0;
|
2023-12-25 00:34:16 +08:00
|
|
|
options.cardsData = result.data;
|
2023-12-22 10:25:55 +08:00
|
|
|
if (options.cardsData.unreviewedCount === 0) {
|
2023-04-12 10:01:08 +08:00
|
|
|
if (result.data.unreviewedCount > 0) {
|
|
|
|
|
newRound(countElement, editor, actionElements, result.data.unreviewedCount);
|
2023-04-12 09:26:19 +08:00
|
|
|
} else {
|
|
|
|
|
allDone(countElement, editor, actionElements);
|
|
|
|
|
}
|
2023-02-24 22:50:33 +08:00
|
|
|
} else {
|
|
|
|
|
nextCard({
|
|
|
|
|
countElement,
|
|
|
|
|
editor,
|
|
|
|
|
actionElements,
|
|
|
|
|
index,
|
2023-12-22 10:25:55 +08:00
|
|
|
blocks: options.cardsData.cards
|
2023-02-26 11:45:50 +08:00
|
|
|
});
|
2023-02-24 22:50:33 +08:00
|
|
|
}
|
|
|
|
|
});
|
2023-02-19 00:05:38 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-02-24 22:50:33 +08:00
|
|
|
nextCard({
|
|
|
|
|
countElement,
|
|
|
|
|
editor,
|
|
|
|
|
actionElements,
|
|
|
|
|
index,
|
2023-12-22 10:25:55 +08:00
|
|
|
blocks: options.cardsData.cards
|
2023-02-26 11:45:50 +08:00
|
|
|
});
|
2022-12-22 15:37:21 +08:00
|
|
|
});
|
2023-02-19 00:05:38 +08:00
|
|
|
}
|
|
|
|
|
});
|
2023-04-28 10:30:27 +08:00
|
|
|
return editor;
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
export const openCard = (app: App) => {
|
2023-04-28 10:30:27 +08:00
|
|
|
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
|
2023-05-18 19:27:21 +08:00
|
|
|
openCardByData(app, cardsResponse.data, "all");
|
2023-04-28 10:30:27 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-18 19:27:21 +08:00
|
|
|
export const openCardByData = (app: App, cardsData: {
|
2023-04-28 10:30:27 +08:00
|
|
|
cards: ICard[],
|
|
|
|
|
unreviewedCount: number
|
2023-12-22 10:25:55 +08:00
|
|
|
unreviewedNewCardCount: number
|
|
|
|
|
unreviewedOldCardCount: number
|
2023-04-28 10:30:27 +08:00
|
|
|
}, cardType: TCardType, id?: string, title?: string) => {
|
|
|
|
|
const exit = window.siyuan.dialogs.find(item => {
|
2023-12-22 12:30:12 +08:00
|
|
|
if (item.element.getAttribute("data-key") === Constants.DIALOG_OPENCARD) {
|
2023-04-28 10:30:27 +08:00
|
|
|
item.destroy();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (exit) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const dialog = new Dialog({
|
2023-12-22 13:09:44 +08:00
|
|
|
positionId: Constants.DIALOG_OPENCARD,
|
2023-12-22 10:25:55 +08:00
|
|
|
content: genCardHTML({id, cardType, cardsData, isTab: false}),
|
2023-12-22 13:09:44 +08:00
|
|
|
width: isMobile() ? "100vw" : "80vw",
|
|
|
|
|
height: isMobile() ? "100vh" : "70vh",
|
2023-04-28 10:30:27 +08:00
|
|
|
destroyCallback() {
|
|
|
|
|
if (editor) {
|
|
|
|
|
editor.destroy();
|
|
|
|
|
if (window.siyuan.mobile) {
|
|
|
|
|
window.siyuan.mobile.popEditor = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
(dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
|
|
|
|
|
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1024px";
|
|
|
|
|
const editor = bindCardEvent({
|
2023-05-18 19:27:21 +08:00
|
|
|
app,
|
2023-04-28 10:30:27 +08:00
|
|
|
element: dialog.element,
|
2023-12-22 10:25:55 +08:00
|
|
|
cardsData,
|
2023-04-28 10:30:27 +08:00
|
|
|
title,
|
|
|
|
|
id,
|
|
|
|
|
cardType,
|
|
|
|
|
dialog
|
|
|
|
|
});
|
2023-09-14 11:58:56 +08:00
|
|
|
dialog.editor = editor;
|
2023-02-19 09:35:07 +08:00
|
|
|
};
|
2023-02-24 22:50:33 +08:00
|
|
|
|
|
|
|
|
const nextCard = (options: {
|
2023-06-01 20:50:49 +08:00
|
|
|
countElement: Element,
|
|
|
|
|
editor: Protyle,
|
|
|
|
|
actionElements: NodeListOf<Element>,
|
|
|
|
|
index: number,
|
|
|
|
|
blocks: ICard[]
|
2023-02-24 22:50:33 +08:00
|
|
|
}) => {
|
2023-03-24 20:54:02 +08:00
|
|
|
options.editor.protyle.element.classList.add("card__block--hide");
|
|
|
|
|
if (window.siyuan.config.flashcard.superBlock) {
|
|
|
|
|
options.editor.protyle.element.classList.add("card__block--hidesb");
|
|
|
|
|
}
|
2023-10-04 11:32:25 +08:00
|
|
|
if (window.siyuan.config.flashcard.heading) {
|
|
|
|
|
options.editor.protyle.element.classList.add("card__block--hideh");
|
|
|
|
|
}
|
2023-03-24 20:54:02 +08:00
|
|
|
if (window.siyuan.config.flashcard.list) {
|
|
|
|
|
options.editor.protyle.element.classList.add("card__block--hideli");
|
|
|
|
|
}
|
2023-03-28 10:21:59 +08:00
|
|
|
if (window.siyuan.config.flashcard.mark) {
|
|
|
|
|
options.editor.protyle.element.classList.add("card__block--hidemark");
|
|
|
|
|
}
|
2023-02-24 22:50:33 +08:00
|
|
|
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");
|
2023-12-22 10:54:47 +08:00
|
|
|
options.countElement.innerHTML = (options.index + 1).toString();
|
|
|
|
|
options.countElement.parentElement.classList.remove("fn__none");
|
2023-02-26 11:34:30 +08:00
|
|
|
if (options.index === 0) {
|
|
|
|
|
options.actionElements[0].firstElementChild.setAttribute("disabled", "disabled");
|
2023-02-26 11:45:50 +08:00
|
|
|
} else {
|
2023-02-26 11:34:30 +08:00
|
|
|
options.actionElements[0].firstElementChild.removeAttribute("disabled");
|
|
|
|
|
}
|
2023-02-24 22:50:33 +08:00
|
|
|
fetchPost("/api/filetree/getDoc", {
|
|
|
|
|
id: options.blocks[options.index].blockID,
|
|
|
|
|
mode: 0,
|
|
|
|
|
size: Constants.SIZE_GET_MAX
|
|
|
|
|
}, (response) => {
|
2023-06-01 14:56:21 +08:00
|
|
|
onGet({
|
|
|
|
|
data: response,
|
|
|
|
|
protyle: options.editor.protyle,
|
2023-10-01 10:49:52 +08:00
|
|
|
action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
2023-06-01 14:56:21 +08:00
|
|
|
});
|
2023-02-24 22:50:33 +08:00
|
|
|
});
|
2023-02-26 11:45:50 +08:00
|
|
|
};
|
2023-02-24 22:50:33 +08:00
|
|
|
|
|
|
|
|
const allDone = (countElement: Element, editor: Protyle, actionElements: NodeListOf<Element>) => {
|
2023-12-25 00:37:12 +08:00
|
|
|
countElement.parentElement.classList.add("fn__none");
|
2023-02-24 22:50:33 +08:00
|
|
|
editor.protyle.element.classList.add("fn__none");
|
2023-04-12 14:48:01 +08:00
|
|
|
const emptyElement = editor.protyle.element.nextElementSibling;
|
|
|
|
|
emptyElement.innerHTML = `<div>🔮</div>${window.siyuan.languages.noDueCard}`;
|
2023-04-12 09:26:19 +08:00
|
|
|
emptyElement.classList.remove("fn__none");
|
2023-02-24 22:50:33 +08:00
|
|
|
actionElements[0].classList.add("fn__none");
|
|
|
|
|
actionElements[1].classList.add("fn__none");
|
|
|
|
|
};
|
2023-04-12 09:26:19 +08:00
|
|
|
|
2023-04-12 10:01:08 +08:00
|
|
|
const newRound = (countElement: Element, editor: Protyle, actionElements: NodeListOf<Element>, unreviewedCount: number) => {
|
2023-04-12 09:26:19 +08:00
|
|
|
countElement.classList.add("fn__none");
|
|
|
|
|
editor.protyle.element.classList.add("fn__none");
|
|
|
|
|
const emptyElement = editor.protyle.element.nextElementSibling;
|
2023-04-12 14:46:17 +08:00
|
|
|
emptyElement.innerHTML = `<div>♻️ </div>
|
|
|
|
|
<span>${window.siyuan.languages.continueReview2.replace("${count}", unreviewedCount)}</span>
|
|
|
|
|
<div class="fn__hr"></div>
|
2023-04-13 08:56:22 +08:00
|
|
|
<button data-type="newround" class="b3-button fn__size200">${window.siyuan.languages.continueReview1}</button>`;
|
2023-04-12 09:26:19 +08:00
|
|
|
emptyElement.classList.remove("fn__none");
|
|
|
|
|
actionElements[0].classList.add("fn__none");
|
|
|
|
|
actionElements[1].classList.add("fn__none");
|
2023-04-12 14:48:01 +08:00
|
|
|
};
|