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-02-20 14:34:22 +08:00
|
|
|
import {disabledProtyle, 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-03-08 22:39:09 +08:00
|
|
|
import {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-27 20:03:00 +08:00
|
|
|
import {newCardTab} from "./newCardTab";
|
2023-04-28 16:01:02 +08:00
|
|
|
/// #endif
|
|
|
|
|
import {getDisplayName, movePathTo} from "../util/pathName";
|
2022-12-22 14:52:43 +08:00
|
|
|
|
2023-04-27 20:03:00 +08:00
|
|
|
export const genCardHTML = (options: {
|
|
|
|
|
id: string,
|
|
|
|
|
cardType: TCardType,
|
|
|
|
|
blocks: ICard[],
|
|
|
|
|
isTab: boolean
|
|
|
|
|
}) => {
|
2023-04-28 16:01:02 +08:00
|
|
|
let iconsHTML:string
|
|
|
|
|
/// #if MOBILE
|
|
|
|
|
iconsHTML=`<div class="toolbar toolbar--border">
|
|
|
|
|
<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>
|
|
|
|
|
<div data-type="count" class="${options.blocks.length === 0 ? "fn__none" : ""}">1/${options.blocks.length}</span></div>
|
|
|
|
|
<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
|
|
|
|
|
iconsHTML=`<div class="block__icons">
|
|
|
|
|
${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>
|
|
|
|
|
<span class="fn__flex-1 fn__flex-center">${window.siyuan.languages.riffCard}</span>`}
|
2023-04-14 12:03:11 +08:00
|
|
|
<span class="fn__space"></span>
|
2023-04-27 20:03:00 +08:00
|
|
|
<div data-type="count" class="ft__on-surface ft__smaller fn__flex-center${options.blocks.length === 0 ? " fn__none" : ""}">1/${options.blocks.length}</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-04-27 20:03:00 +08:00
|
|
|
<div class="card__block fn__flex-1${options.blocks.length === 0 ? " fn__none" : ""}${window.siyuan.config.flashcard.mark ? " card__block--hidemark" : ""}${window.siyuan.config.flashcard.superBlock ? " card__block--hidesb" : ""}${window.siyuan.config.flashcard.list ? " card__block--hideli" : ""}" data-type="render"></div>
|
|
|
|
|
<div class="card__empty card__empty--space${options.blocks.length === 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-04-27 20:03:00 +08:00
|
|
|
<div class="fn__flex card__action${options.blocks.length === 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-02-26 10:49:15 +08:00
|
|
|
<button data-type="-1" class="b3-button fn__flex-1">${window.siyuan.languages.cardShowAnswer} (${window.siyuan.languages.space})</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-04-28 10:30:27 +08:00
|
|
|
<button data-type="0" 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-04-28 10:30:27 +08:00
|
|
|
<button data-type="1" 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-04-28 10:30:27 +08:00
|
|
|
<button data-type="2" aria-label="3 / l" 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-04-28 10:30:27 +08:00
|
|
|
<button data-type="3" 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: {
|
|
|
|
|
element: Element,
|
|
|
|
|
title?: string,
|
|
|
|
|
blocks: ICard[],
|
|
|
|
|
cardType: TCardType,
|
|
|
|
|
id?: string,
|
2023-04-28 12:02:08 +08:00
|
|
|
dialog?: Dialog,
|
2023-04-28 10:30:27 +08:00
|
|
|
}) => {
|
2023-04-27 20:03:00 +08:00
|
|
|
let index = 0;
|
2023-04-28 10:30:27 +08:00
|
|
|
const editor = new Protyle(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-02-20 14:34:22 +08:00
|
|
|
if (window.siyuan.config.editor.readOnly) {
|
|
|
|
|
disabledProtyle(editor.protyle);
|
|
|
|
|
}
|
2023-04-28 10:30:27 +08:00
|
|
|
if (options.blocks.length > 0) {
|
2023-02-19 00:05:38 +08:00
|
|
|
fetchPost("/api/filetree/getDoc", {
|
2023-04-28 10:30:27 +08:00
|
|
|
id: options.blocks[index].blockID,
|
2023-02-19 00:05:38 +08:00
|
|
|
mode: 0,
|
|
|
|
|
size: Constants.SIZE_GET_MAX
|
|
|
|
|
}, (response) => {
|
|
|
|
|
onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-28 10:30:27 +08:00
|
|
|
(options.element.firstElementChild as HTMLElement).style.zIndex = "200";
|
|
|
|
|
options.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom);
|
|
|
|
|
const countElement = options.element.querySelector('[data-type="count"]');
|
|
|
|
|
const actionElements = options.element.querySelectorAll(".card__action");
|
|
|
|
|
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-04-28 10:30:27 +08:00
|
|
|
options.blocks = treeCards.data.cards;
|
|
|
|
|
if (options.blocks.length > 0) {
|
2023-04-14 12:03:11 +08:00
|
|
|
nextCard({
|
|
|
|
|
countElement,
|
|
|
|
|
editor,
|
|
|
|
|
actionElements,
|
|
|
|
|
index,
|
2023-04-28 10:30:27 +08:00
|
|
|
blocks: options.blocks
|
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 = "0";
|
2023-02-23 18:57:04 +08:00
|
|
|
} else if (event.detail === "2" || event.detail === "k") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "1";
|
2023-02-23 18:57:04 +08:00
|
|
|
} else if (event.detail === "3" || event.detail === "l") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "2";
|
2023-02-23 18:57:04 +08:00
|
|
|
} else if (event.detail === "4" || event.detail === ";") {
|
2023-02-19 00:05:38 +08:00
|
|
|
type = "3";
|
2023-02-26 11:34:30 +08:00
|
|
|
} else if (event.detail === " ") {
|
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-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) {
|
|
|
|
|
newCardTab({
|
2023-04-28 10:30:27 +08:00
|
|
|
cardType: filterElement.getAttribute("data-cardtype") as TCardType,
|
2023-04-27 20:03:00 +08:00
|
|
|
id: filterElement.getAttribute("data-id"),
|
2023-04-28 10:30:27 +08:00
|
|
|
title: options.title
|
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-04-28 10:30:27 +08:00
|
|
|
if (!type || !options.blocks[index]) {
|
2023-02-19 00:05:38 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2023-02-19 09:55:34 +08:00
|
|
|
hideElements(["toolbar", "hint", "util"], 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")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-28 10:21:59 +08:00
|
|
|
editor.protyle.element.classList.remove("card__block--hidemark", "card__block--hideli", "card__block--hidesb");
|
2023-02-19 00:05:38 +08:00
|
|
|
actionElements[0].classList.add("fn__none");
|
|
|
|
|
actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => {
|
2023-03-19 14:50:08 +08:00
|
|
|
if (btnIndex !== 0) {
|
2023-04-28 10:30:27 +08:00
|
|
|
element.previousElementSibling.textContent = options.blocks[index].nextDues[btnIndex - 1];
|
2023-03-19 14:50:08 +08:00
|
|
|
}
|
2022-12-22 22:19:04 +08:00
|
|
|
});
|
2023-02-19 00:05:38 +08:00
|
|
|
actionElements[1].classList.remove("fn__none");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-24 20:54:02 +08:00
|
|
|
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-04-28 10:30:27 +08:00
|
|
|
blocks: options.blocks
|
2023-02-26 11:45:50 +08:00
|
|
|
});
|
2023-02-26 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-19 14:50:08 +08:00
|
|
|
if (["0", "1", "2", "3", "-3"].includes(type) && actionElements[0].classList.contains("fn__none")) {
|
|
|
|
|
fetchPost(type === "-3" ? "/api/riff/skipReviewRiffCard" : "/api/riff/reviewRiffCard", {
|
2023-04-28 10:30:27 +08:00
|
|
|
deckID: options.blocks[index].deckID,
|
|
|
|
|
cardID: options.blocks[index].cardID,
|
2023-03-22 14:32:29 +08:00
|
|
|
rating: parseInt(type),
|
2023-04-28 10:30:27 +08:00
|
|
|
reviewedCards: options.blocks
|
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" &&
|
|
|
|
|
(0 !== window.siyuan.config.sync.provider || (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-04-28 10:30:27 +08:00
|
|
|
if (index > options.blocks.length - 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-04-28 10:30:27 +08:00
|
|
|
reviewedCards: options.blocks
|
2023-04-12 10:01:08 +08:00
|
|
|
}, (result) => {
|
2023-02-26 11:45:50 +08:00
|
|
|
index = 0;
|
2023-04-28 10:30:27 +08:00
|
|
|
options.blocks = result.data.cards;
|
|
|
|
|
if (options.blocks.length === 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-04-28 10:30:27 +08:00
|
|
|
blocks: options.blocks
|
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-04-28 10:30:27 +08:00
|
|
|
blocks: options.blocks
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const openCard = () => {
|
|
|
|
|
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
|
|
|
|
|
openCardByData(cardsResponse.data, "all");
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const openCardByData = (cardsData: {
|
|
|
|
|
cards: ICard[],
|
|
|
|
|
unreviewedCount: number
|
|
|
|
|
}, cardType: TCardType, id?: string, title?: string) => {
|
|
|
|
|
const exit = window.siyuan.dialogs.find(item => {
|
|
|
|
|
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.riffCard.custom) {
|
|
|
|
|
item.destroy();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (exit) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dialog = new Dialog({
|
|
|
|
|
content: genCardHTML({id, cardType, blocks: cardsData.cards, isTab: false}),
|
|
|
|
|
width: isMobile() ? "100vw" : "80vw",
|
|
|
|
|
height: isMobile() ? "100vh" : "70vh",
|
|
|
|
|
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({
|
|
|
|
|
element: dialog.element,
|
|
|
|
|
blocks: cardsData.cards,
|
|
|
|
|
title,
|
|
|
|
|
id,
|
|
|
|
|
cardType,
|
|
|
|
|
dialog
|
|
|
|
|
});
|
2023-02-19 09:35:07 +08:00
|
|
|
};
|
2023-02-24 22:50:33 +08:00
|
|
|
|
|
|
|
|
const nextCard = (options: {
|
|
|
|
|
countElement: Element, editor: Protyle, actionElements: NodeListOf<Element>, index: number, blocks: ICard[]
|
|
|
|
|
}) => {
|
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");
|
|
|
|
|
}
|
|
|
|
|
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-04-14 12:03:11 +08:00
|
|
|
options.countElement.innerHTML = `${options.index + 1}/${options.blocks.length}`;
|
2023-02-24 22:50:33 +08:00
|
|
|
options.countElement.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) => {
|
|
|
|
|
onGet(response, options.editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
|
|
|
|
|
});
|
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>) => {
|
|
|
|
|
countElement.classList.add("fn__none");
|
|
|
|
|
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
|
|
|
};
|