-
-
-
-
-
-
-
-
${countHTML}
+ openCardByData(cardsResponse.data, `
`)
+ });
+ });
+};
+
+export const openCardByData = (cardsData: ICard[], html = "") => {
+ let blocks = cardsData;
+ let index = 0;
+ if (blocks.length > 0) {
+ html += `
+
+
+
+
+
+
1/${blocks.length}
+
`;
+ }
+ const dialog = new Dialog({
+ content: `
+
+ ${window.siyuan.languages.riffCard}
+ ${html}
-
${window.siyuan.languages.noDueCard}
+
+
🎉
+ ${window.siyuan.languages.noDueCard}
+
-
+
@@ -70,22 +79,96 @@ export const openCard = () => {
`,
- width: isMobile() ? "98vw" : "80vw",
- height: isMobile() ? "80vh" : "70vh",
+ width: isMobile() ? "98vw" : "80vw",
+ height: isMobile() ? "80vh" : "70vh",
+ });
+ (dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
+ const editor = new Protyle(dialog.element.querySelector("[data-type='render']") as HTMLElement, {
+ blockId: "",
+ action: [Constants.CB_GET_ALL],
+ render: {
+ background: false,
+ title: false,
+ gutter: true,
+ breadcrumbDocName: true,
+ },
+ typewriterMode: false
+ });
+ if (blocks.length > 0) {
+ fetchPost("/api/filetree/getDoc", {
+ id: blocks[index].blockID,
+ mode: 0,
+ size: Constants.SIZE_GET_MAX
+ }, (response) => {
+ onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
+ });
+ }
+ (dialog.element.firstElementChild as HTMLElement).style.zIndex = "200";
+ dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom);
+ const countElement = dialog.element.querySelector('[data-type="count"]');
+ const actionElements = dialog.element.querySelectorAll(".b3-dialog__cardaction");
+ dialog.element.addEventListener("click", (event) => {
+ const viewElement = hasClosestByAttribute(event.target as HTMLElement, "data-type", "view");
+ if (viewElement) {
+ // TODO 文档卡
+ viewCards(selectElement.value, selectElement.options[selectElement.selectedIndex].text);
+ event.preventDefault();
+ event.stopPropagation();
+ return;
+ }
+ let type = "";
+ if (typeof event.detail === "string") {
+ if (event.detail === "a") {
+ type = "0";
+ } else if (event.detail === "h") {
+ type = "1";
+ } else if (event.detail === "g") {
+ type = "2";
+ } else if (event.detail === "e") {
+ type = "3";
+ } else if (event.detail === "s") {
+ type = "-1";
+ }
+ }
+ if (!type) {
+ const buttonElement = hasClosestByClassName(event.target as HTMLElement, "b3-button");
+ if (buttonElement) {
+ type = buttonElement.getAttribute("data-type");
+ }
+ }
+ if (!type || !blocks[index]) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ if (type === "-1") {
+ editor.protyle.element.classList.remove("b3-dialog__cardblock--hide");
+ actionElements[0].classList.add("fn__none");
+ actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => {
+ element.previousElementSibling.textContent = blocks[index].nextDues[btnIndex];
});
- (dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
- const editor = new Protyle(dialog.element.querySelector("[data-type='render']") as HTMLElement, {
- blockId: "",
- action: [Constants.CB_GET_ALL],
- render: {
- background: false,
- title: false,
- gutter: true,
- breadcrumbDocName: true,
- },
- typewriterMode: false
- });
- if (blocks.length > 0) {
+ actionElements[1].classList.remove("fn__none");
+ return;
+ }
+ if (["0", "1", "2", "3"].includes(type)) {
+ fetchPost("/api/riff/reviewRiffCard", {
+ deckID: blocks[index].deckID,
+ blockID: blocks[index].blockID,
+ rating: parseInt(type)
+ }, () => {
+ index++;
+ editor.protyle.element.classList.add("b3-dialog__cardblock--hide");
+ if (index > blocks.length - 1) {
+ countElement.classList.add("fn__none");
+ editor.protyle.element.classList.add("fn__none");
+ editor.protyle.element.nextElementSibling.classList.remove("fn__none");
+ actionElements[0].classList.add("fn__none");
+ actionElements[1].classList.add("fn__none");
+ return;
+ }
+ actionElements[0].classList.remove("fn__none");
+ actionElements[1].classList.add("fn__none");
+ countElement.lastElementChild.firstElementChild.innerHTML = (index + 1).toString();
fetchPost("/api/filetree/getDoc", {
id: blocks[index].blockID,
mode: 0,
@@ -93,111 +176,39 @@ export const openCard = () => {
}, (response) => {
onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
});
- }
- (dialog.element.firstElementChild as HTMLElement).style.zIndex = "200";
- dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom);
- const countElement = dialog.element.querySelector('[data-type="count"]');
- const actionElements = dialog.element.querySelectorAll(".b3-dialog__cardaction");
- const selectElement = dialog.element.querySelector("select");
- selectElement.addEventListener("change", () => {
- fetchPost("/api/riff/getRiffDueCards", {deckID: selectElement.value}, (cardsChangeResponse) => {
- blocks = cardsChangeResponse.data;
- index = 0;
- editor.protyle.element.classList.add("b3-dialog__cardblock--hide");
- if (blocks.length > 0) {
- countElement.innerHTML = `
1/${blocks.length}`;
- countElement.classList.remove("fn__none");
- editor.protyle.element.classList.remove("fn__none");
- editor.protyle.element.nextElementSibling.classList.add("fn__none");
- actionElements[0].classList.remove("fn__none");
- actionElements[1].classList.add("fn__none");
- fetchPost("/api/filetree/getDoc", {
- id: blocks[index].blockID,
- mode: 0,
- size: Constants.SIZE_GET_MAX
- }, (response) => {
- onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
- });
- } else {
- countElement.classList.add("fn__none");
- editor.protyle.element.classList.add("fn__none");
- editor.protyle.element.nextElementSibling.classList.remove("fn__none");
- actionElements[0].classList.add("fn__none");
- actionElements[1].classList.add("fn__none");
- }
+ });
+ }
+ });
+ const selectElement = dialog.element.querySelector("select");
+ if (!selectElement) {
+ return
+ }
+ selectElement.addEventListener("change", () => {
+ fetchPost("/api/riff/getRiffDueCards", {deckID: selectElement.value}, (cardsChangeResponse) => {
+ blocks = cardsChangeResponse.data;
+ index = 0;
+ editor.protyle.element.classList.add("b3-dialog__cardblock--hide");
+ if (blocks.length > 0) {
+ countElement.lastElementChild.innerHTML = `
1/${blocks.length}`;
+ countElement.classList.remove("fn__none");
+ editor.protyle.element.classList.remove("fn__none");
+ editor.protyle.element.nextElementSibling.classList.add("fn__none");
+ actionElements[0].classList.remove("fn__none");
+ actionElements[1].classList.add("fn__none");
+ fetchPost("/api/filetree/getDoc", {
+ id: blocks[index].blockID,
+ mode: 0,
+ size: Constants.SIZE_GET_MAX
+ }, (response) => {
+ onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
});
- });
- dialog.element.addEventListener("click", (event) => {
- const viewElement = hasClosestByAttribute(event.target as HTMLElement, "data-type", "view");
- if (viewElement) {
- viewCards(selectElement.value, selectElement.options[selectElement.selectedIndex].text);
- event.preventDefault();
- event.stopPropagation();
- return;
- }
- let type = "";
- if (typeof event.detail === "string") {
- if (event.detail === "a") {
- type = "0";
- } else if (event.detail === "h") {
- type = "1";
- } else if (event.detail === "g") {
- type = "2";
- } else if (event.detail === "e") {
- type = "3";
- } else if (event.detail === "s") {
- type = "-1";
- }
- }
- if (!type) {
- const buttonElement = hasClosestByClassName(event.target as HTMLElement, "b3-button");
- if (buttonElement) {
- type = buttonElement.getAttribute("data-type");
- }
- }
- if (!type || !blocks[index]) {
- return;
- }
- event.preventDefault();
- event.stopPropagation();
- if (type === "-1") {
- editor.protyle.element.classList.remove("b3-dialog__cardblock--hide");
- actionElements[0].classList.add("fn__none");
- actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => {
- element.previousElementSibling.textContent = blocks[index].nextDues[btnIndex];
- });
- actionElements[1].classList.remove("fn__none");
- return;
- }
- if (["0", "1", "2", "3"].includes(type)) {
- fetchPost("/api/riff/reviewRiffCard", {
- deckID: blocks[index].deckID,
- blockID: blocks[index].blockID,
- rating: parseInt(type)
- }, () => {
- index++;
- editor.protyle.element.classList.add("b3-dialog__cardblock--hide");
- if (index > blocks.length - 1) {
- countElement.classList.add("fn__none");
- editor.protyle.element.classList.add("fn__none");
- editor.protyle.element.nextElementSibling.classList.remove("fn__none");
- actionElements[0].classList.add("fn__none");
- actionElements[1].classList.add("fn__none");
- return;
- }
- actionElements[0].classList.remove("fn__none");
- actionElements[1].classList.add("fn__none");
- countElement.firstElementChild.innerHTML = (index + 1).toString();
- fetchPost("/api/filetree/getDoc", {
- id: blocks[index].blockID,
- mode: 0,
- size: Constants.SIZE_GET_MAX
- }, (response) => {
- onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
- });
- });
- }
- });
+ } else {
+ countElement.classList.add("fn__none");
+ editor.protyle.element.classList.add("fn__none");
+ editor.protyle.element.nextElementSibling.classList.remove("fn__none");
+ actionElements[0].classList.add("fn__none");
+ actionElements[1].classList.add("fn__none");
+ }
});
});
-};
+}
diff --git a/app/src/card/viewCards.ts b/app/src/card/viewCards.ts
index b1e5df000..9c3e35dad 100644
--- a/app/src/card/viewCards.ts
+++ b/app/src/card/viewCards.ts
@@ -16,19 +16,17 @@ export const viewCards = (deckID: string, title: string, sourceElement?: HTMLEle
let edit: Protyle;
fetchPost("/api/riff/getRiffCards", {deckID, page: pageIndex}, (response) => {
const dialog = new Dialog({
- title,
content: `
-
-
+
-
${renderViewItem(response.data.blocks)}
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 44d5f2381..1cdabd789 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -32,7 +32,7 @@ import {mathRender} from "../markdown/mathRender";
import {duplicateBlock} from "../wysiwyg/commonHotkey";
import {movePathTo} from "../../util/pathName";
import {hintMoveBlock} from "../hint/extend";
-import {makeCard} from "../../card/makeCard";
+import {makeCard, quickMakeCard} from "../../card/makeCard";
import {transferBlockRef} from "../../menus/block";
export class Gutter {
@@ -667,7 +667,15 @@ export class Gutter {
this.genWidths(selectsElement, protyle);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
- label: window.siyuan.languages.riffCard,
+ label: window.siyuan.languages.quickMakeCard,
+ iconHTML:``,
+ icon: "iconRiffCard",
+ click() {
+ quickMakeCard(selectsElement);
+ }
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.addToDeck,
icon: "iconRiffCard",
click() {
makeCard(selectsElement);
@@ -1431,7 +1439,15 @@ export class Gutter {
}
if (type !== "NodeThematicBreak") {
window.siyuan.menus.menu.append(new MenuItem({
- label: window.siyuan.languages.riffCard,
+ label: window.siyuan.languages.quickMakeCard,
+ iconHTML:``,
+ icon: "iconRiffCard",
+ click() {
+ quickMakeCard([nodeElement]);
+ }
+ }).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.addToDeck,
icon: "iconRiffCard",
click() {
makeCard([nodeElement]);
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index b56947def..226aa4404 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -33,6 +33,7 @@ import {genEmptyElement} from "../../block/util";
import {transaction} from "../wysiwyg/transaction";
import {hideTooltip} from "../../dialog/tooltip";
import {transferBlockRef} from "../../menus/block";
+import {openCardByData} from "../../card/openCard";
export class Title {
public element: HTMLElement;
@@ -230,7 +231,9 @@ export class Title {
}).element);
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
});
- this.element.querySelector(".protyle-attr").addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
+ this.element.querySelector(".protyle-attr").addEventListener("click", (event: MouseEvent & {
+ target: HTMLElement
+ }) => {
fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID
}, (response) => {
@@ -353,6 +356,15 @@ export class Title {
openFileWechatNotify(protyle);
}
}).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ label: window.siyuan.languages.riffCard,
+ icon: "iconRiffCard",
+ click: () => {
+ fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
+ openCardByData(response.data, `${escapeHtml(this.editElement.textContent)}`);
+ });
+ }
+ }).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
iconHTML: Constants.ZWSP,
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 96f2ed503..b692a5d15 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -59,13 +59,19 @@ interface IWorkspace {
closed: boolean
}
-interface ICard {
+interface ICardPackage {
id: string
updated: string
name: string
size: number
}
+interface ICard {
+ blockID: string
+ deckID: string
+ nextDues: IObject
+}
+
interface ISearchOption {
name?: string
sort: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序