mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
879494a71c
commit
cd85db32e5
6 changed files with 57 additions and 63 deletions
|
|
@ -33,23 +33,15 @@ export const genCardItem = (item: ICardPackage) => {
|
|||
</li>`;
|
||||
};
|
||||
|
||||
export const makeCard = (nodeElement: Element[]) => {
|
||||
export const makeCard = (ids: string[]) => {
|
||||
window.siyuan.dialogs.find(item => {
|
||||
if (item.element.getAttribute("data-key") === "makeCard") {
|
||||
hideElements(["dialog"]);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
const range = getEditorRange(nodeElement[0]);
|
||||
fetchPost("/api/riff/getRiffDecks", {}, (response) => {
|
||||
let html = "";
|
||||
const ids: string[] = [];
|
||||
nodeElement.forEach(item => {
|
||||
if (item.getAttribute("data-type") === "NodeThematicBreak") {
|
||||
return;
|
||||
}
|
||||
ids.push(item.getAttribute("data-node-id"));
|
||||
});
|
||||
response.data.forEach((item: ICardPackage) => {
|
||||
html += genCardItem(item);
|
||||
});
|
||||
|
|
@ -69,9 +61,6 @@ export const makeCard = (nodeElement: Element[]) => {
|
|||
<div class="fn__hr"></div>
|
||||
<ul class="b3-list b3-list--background fn__flex-1">${html}</ul>
|
||||
</div>`,
|
||||
destroyCallback() {
|
||||
focusByRange(range);
|
||||
}
|
||||
});
|
||||
dialog.element.setAttribute("data-key", "makeCard");
|
||||
dialog.element.style.zIndex = "200";
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import {isMobile} from "../util/functions";
|
|||
import {Protyle} from "../protyle";
|
||||
import {Constants} from "../constants";
|
||||
import {disabledProtyle, onGet} from "../protyle/util/onGet";
|
||||
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {viewCards} from "./viewCards";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {hideElements} from "../protyle/ui/hideElements";
|
||||
|
||||
export const openCard = () => {
|
||||
|
|
@ -35,10 +34,6 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
|||
if (blocks.length > 0) {
|
||||
html += `<div class="fn__flex" style="align-items: center" data-type="count">
|
||||
<span class="fn__space"></span>
|
||||
<span data-type="view" class="block__icon block__icon--show b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.cardPreview}">
|
||||
<svg><use xlink:href="#iconEye"></use></svg>
|
||||
</span>
|
||||
<span class="fn__space"></span>
|
||||
<div class="ft__on-surface ft__smaller"><span>1</span>/<span>${blocks.length}</span></div>
|
||||
</div>`;
|
||||
}
|
||||
|
|
@ -127,17 +122,6 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
|||
const selectElement = dialog.element.querySelector("select");
|
||||
const titleElement = countElement.previousElementSibling;
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
const viewElement = hasClosestByAttribute(event.target as HTMLElement, "data-type", "view");
|
||||
if (viewElement) {
|
||||
if (selectElement) {
|
||||
viewCards(selectElement.value, selectElement.options[selectElement.selectedIndex].text);
|
||||
} else {
|
||||
viewCards(titleElement.getAttribute("data-id"), titleElement.textContent, undefined, true);
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
let type = "";
|
||||
if (typeof event.detail === "string") {
|
||||
if (event.detail === "1" || event.detail === "j") {
|
||||
|
|
@ -204,9 +188,11 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
|||
index++;
|
||||
editor.protyle.element.classList.add("card__block--hide");
|
||||
if (index > blocks.length - 1) {
|
||||
fetchPost(selectElement ? "/api/riff/getRiffDueCards" : "/api/riff/getTreeRiffDueCards", {
|
||||
fetchPost(selectElement ? "/api/riff/getRiffDueCards" :
|
||||
(titleElement.getAttribute("data-id") ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
|
||||
rootID: titleElement.getAttribute("data-id"),
|
||||
deckID: selectElement?.value
|
||||
deckID: selectElement?.value,
|
||||
notebook: titleElement.getAttribute("data-notebookid"),
|
||||
}, (treeCards) => {
|
||||
index = 0;
|
||||
blocks = treeCards.data;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import {Files} from "../layout/dock/Files";
|
|||
import {openNewWindowById} from "../window/openNewWindow";
|
||||
import {openCardByData} from "../card/openCard";
|
||||
import {escapeHtml} from "../util/escape";
|
||||
import {makeCard} from "../card/makeCard";
|
||||
|
||||
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
||||
const fileItemElement = Array.from(selectItemElements).find(item => {
|
||||
|
|
@ -119,7 +120,7 @@ export const initNavigationMenu = (liElement: HTMLElement) => {
|
|||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
||||
click: () => {
|
||||
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
||||
openCardByData(response.data, `<span data-id="${notebookId}" class="fn__flex-center">${escapeHtml(name)}</span>`);
|
||||
openCardByData(response.data, `<span data-notebookid="${notebookId}" class="fn__flex-center">${escapeHtml(name)}</span>`);
|
||||
});
|
||||
}
|
||||
}).element);
|
||||
|
|
@ -308,12 +309,21 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
|||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.riffCard,
|
||||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
||||
click: () => {
|
||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
||||
openCardByData(response.data, `<span data-id="${id}" class="fn__flex-center">${escapeHtml(name)}</span>`);
|
||||
});
|
||||
}
|
||||
type: "submenu",
|
||||
icon: "iconRiffCard",
|
||||
submenu: [{
|
||||
label: window.siyuan.languages.spaceRepetition,
|
||||
click: () => {
|
||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
||||
openCardByData(response.data, `<span data-id="${id}" class="fn__flex-center">${escapeHtml(name)}</span>`);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
label: window.siyuan.languages.addToDeck,
|
||||
click: () => {
|
||||
makeCard([id]);
|
||||
}
|
||||
}],
|
||||
}).element);
|
||||
/// #if !MOBILE
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
|||
|
|
@ -135,8 +135,8 @@ export const workspaceMenu = (rect: DOMRect) => {
|
|||
}).element);
|
||||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.riffCard,
|
||||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
||||
label: window.siyuan.languages.spaceRepetition,
|
||||
icon: "iconRiffCard",
|
||||
accelerator: window.siyuan.config.keymap.general.riffCard.custom,
|
||||
click: () => {
|
||||
openCard();
|
||||
|
|
|
|||
|
|
@ -677,7 +677,14 @@ export class Gutter {
|
|||
label: window.siyuan.languages.addToDeck,
|
||||
icon: "iconRiffCard",
|
||||
click() {
|
||||
makeCard(selectsElement);
|
||||
const ids: string[] = [];
|
||||
selectsElement.forEach(item => {
|
||||
if (item.getAttribute("data-type") === "NodeThematicBreak") {
|
||||
return;
|
||||
}
|
||||
ids.push(item.getAttribute("data-node-id"));
|
||||
});
|
||||
makeCard(ids);
|
||||
}
|
||||
}).element);
|
||||
return window.siyuan.menus.menu;
|
||||
|
|
@ -1450,7 +1457,7 @@ export class Gutter {
|
|||
label: window.siyuan.languages.addToDeck,
|
||||
icon: "iconRiffCard",
|
||||
click() {
|
||||
makeCard([nodeElement]);
|
||||
makeCard([nodeElement.getAttribute("data-node-id")]);
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
|
|
|
|||
|
|
@ -364,28 +364,30 @@ export class Title {
|
|||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.riffCard,
|
||||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
||||
click: () => {
|
||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
||||
openCardByData(response.data, `<span data-id="${protyle.block.rootID}" class="fn__flex-center">${escapeHtml(this.editElement.textContent)}</span>`);
|
||||
});
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.quickMakeCard,
|
||||
accelerator: window.siyuan.config.keymap.editor.general.quickMakeCard.custom,
|
||||
iconHTML: '<svg class="b3-menu__icon" style="color:var(--b3-theme-primary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
||||
type: "submenu",
|
||||
icon: "iconRiffCard",
|
||||
click: () => {
|
||||
quickMakeCard([this.element]);
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.addToDeck,
|
||||
icon: "iconRiffCard",
|
||||
click: () => {
|
||||
makeCard([this.element]);
|
||||
}
|
||||
submenu: [{
|
||||
iconHTML: Constants.ZWSP,
|
||||
label: window.siyuan.languages.spaceRepetition,
|
||||
click: () => {
|
||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
||||
openCardByData(response.data, `<span data-id="${protyle.block.rootID}" class="fn__flex-center">${escapeHtml(this.editElement.textContent)}</span>`);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
label: window.siyuan.languages.quickMakeCard,
|
||||
accelerator: window.siyuan.config.keymap.editor.general.quickMakeCard.custom,
|
||||
click: () => {
|
||||
quickMakeCard([this.element]);
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
label: window.siyuan.languages.addToDeck,
|
||||
click: () => {
|
||||
makeCard([protyle.block.rootID]);
|
||||
}
|
||||
}],
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue