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>`;
|
</li>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const makeCard = (nodeElement: Element[]) => {
|
export const makeCard = (ids: string[]) => {
|
||||||
window.siyuan.dialogs.find(item => {
|
window.siyuan.dialogs.find(item => {
|
||||||
if (item.element.getAttribute("data-key") === "makeCard") {
|
if (item.element.getAttribute("data-key") === "makeCard") {
|
||||||
hideElements(["dialog"]);
|
hideElements(["dialog"]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const range = getEditorRange(nodeElement[0]);
|
|
||||||
fetchPost("/api/riff/getRiffDecks", {}, (response) => {
|
fetchPost("/api/riff/getRiffDecks", {}, (response) => {
|
||||||
let html = "";
|
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) => {
|
response.data.forEach((item: ICardPackage) => {
|
||||||
html += genCardItem(item);
|
html += genCardItem(item);
|
||||||
});
|
});
|
||||||
|
|
@ -69,9 +61,6 @@ export const makeCard = (nodeElement: Element[]) => {
|
||||||
<div class="fn__hr"></div>
|
<div class="fn__hr"></div>
|
||||||
<ul class="b3-list b3-list--background fn__flex-1">${html}</ul>
|
<ul class="b3-list b3-list--background fn__flex-1">${html}</ul>
|
||||||
</div>`,
|
</div>`,
|
||||||
destroyCallback() {
|
|
||||||
focusByRange(range);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
dialog.element.setAttribute("data-key", "makeCard");
|
dialog.element.setAttribute("data-key", "makeCard");
|
||||||
dialog.element.style.zIndex = "200";
|
dialog.element.style.zIndex = "200";
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import {isMobile} from "../util/functions";
|
||||||
import {Protyle} from "../protyle";
|
import {Protyle} from "../protyle";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {disabledProtyle, onGet} from "../protyle/util/onGet";
|
import {disabledProtyle, onGet} from "../protyle/util/onGet";
|
||||||
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||||
import {viewCards} from "./viewCards";
|
|
||||||
import {hideElements} from "../protyle/ui/hideElements";
|
import {hideElements} from "../protyle/ui/hideElements";
|
||||||
|
|
||||||
export const openCard = () => {
|
export const openCard = () => {
|
||||||
|
|
@ -35,10 +34,6 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
||||||
if (blocks.length > 0) {
|
if (blocks.length > 0) {
|
||||||
html += `<div class="fn__flex" style="align-items: center" data-type="count">
|
html += `<div class="fn__flex" style="align-items: center" data-type="count">
|
||||||
<span class="fn__space"></span>
|
<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 class="ft__on-surface ft__smaller"><span>1</span>/<span>${blocks.length}</span></div>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
@ -127,17 +122,6 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
||||||
const selectElement = dialog.element.querySelector("select");
|
const selectElement = dialog.element.querySelector("select");
|
||||||
const titleElement = countElement.previousElementSibling;
|
const titleElement = countElement.previousElementSibling;
|
||||||
dialog.element.addEventListener("click", (event) => {
|
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 = "";
|
let type = "";
|
||||||
if (typeof event.detail === "string") {
|
if (typeof event.detail === "string") {
|
||||||
if (event.detail === "1" || event.detail === "j") {
|
if (event.detail === "1" || event.detail === "j") {
|
||||||
|
|
@ -204,9 +188,11 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
||||||
index++;
|
index++;
|
||||||
editor.protyle.element.classList.add("card__block--hide");
|
editor.protyle.element.classList.add("card__block--hide");
|
||||||
if (index > blocks.length - 1) {
|
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"),
|
rootID: titleElement.getAttribute("data-id"),
|
||||||
deckID: selectElement?.value
|
deckID: selectElement?.value,
|
||||||
|
notebook: titleElement.getAttribute("data-notebookid"),
|
||||||
}, (treeCards) => {
|
}, (treeCards) => {
|
||||||
index = 0;
|
index = 0;
|
||||||
blocks = treeCards.data;
|
blocks = treeCards.data;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import {Files} from "../layout/dock/Files";
|
||||||
import {openNewWindowById} from "../window/openNewWindow";
|
import {openNewWindowById} from "../window/openNewWindow";
|
||||||
import {openCardByData} from "../card/openCard";
|
import {openCardByData} from "../card/openCard";
|
||||||
import {escapeHtml} from "../util/escape";
|
import {escapeHtml} from "../util/escape";
|
||||||
|
import {makeCard} from "../card/makeCard";
|
||||||
|
|
||||||
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
||||||
const fileItemElement = Array.from(selectItemElements).find(item => {
|
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>',
|
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
||||||
click: () => {
|
click: () => {
|
||||||
fetchPost("/api/riff/getNotebookRiffDueCards", {notebook: notebookId}, (response) => {
|
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);
|
}).element);
|
||||||
|
|
@ -308,12 +309,21 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement:
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.riffCard,
|
label: window.siyuan.languages.riffCard,
|
||||||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
type: "submenu",
|
||||||
click: () => {
|
icon: "iconRiffCard",
|
||||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
|
submenu: [{
|
||||||
openCardByData(response.data, `<span data-id="${id}" class="fn__flex-center">${escapeHtml(name)}</span>`);
|
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);
|
}).element);
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,8 @@ export const workspaceMenu = (rect: DOMRect) => {
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.riffCard,
|
label: window.siyuan.languages.spaceRepetition,
|
||||||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
icon: "iconRiffCard",
|
||||||
accelerator: window.siyuan.config.keymap.general.riffCard.custom,
|
accelerator: window.siyuan.config.keymap.general.riffCard.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openCard();
|
openCard();
|
||||||
|
|
|
||||||
|
|
@ -677,7 +677,14 @@ export class Gutter {
|
||||||
label: window.siyuan.languages.addToDeck,
|
label: window.siyuan.languages.addToDeck,
|
||||||
icon: "iconRiffCard",
|
icon: "iconRiffCard",
|
||||||
click() {
|
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);
|
}).element);
|
||||||
return window.siyuan.menus.menu;
|
return window.siyuan.menus.menu;
|
||||||
|
|
@ -1450,7 +1457,7 @@ export class Gutter {
|
||||||
label: window.siyuan.languages.addToDeck,
|
label: window.siyuan.languages.addToDeck,
|
||||||
icon: "iconRiffCard",
|
icon: "iconRiffCard",
|
||||||
click() {
|
click() {
|
||||||
makeCard([nodeElement]);
|
makeCard([nodeElement.getAttribute("data-node-id")]);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
|
||||||
|
|
@ -364,28 +364,30 @@ export class Title {
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.riffCard,
|
label: window.siyuan.languages.riffCard,
|
||||||
iconHTML: '<svg class="b3-menu__icon" style="color: var(--b3-theme-secondary)"><use xlink:href="#iconRiffCard"></use></svg>',
|
type: "submenu",
|
||||||
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>',
|
|
||||||
icon: "iconRiffCard",
|
icon: "iconRiffCard",
|
||||||
click: () => {
|
submenu: [{
|
||||||
quickMakeCard([this.element]);
|
iconHTML: Constants.ZWSP,
|
||||||
}
|
label: window.siyuan.languages.spaceRepetition,
|
||||||
}).element);
|
click: () => {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
||||||
label: window.siyuan.languages.addToDeck,
|
openCardByData(response.data, `<span data-id="${protyle.block.rootID}" class="fn__flex-center">${escapeHtml(this.editElement.textContent)}</span>`);
|
||||||
icon: "iconRiffCard",
|
});
|
||||||
click: () => {
|
}
|
||||||
makeCard([this.element]);
|
}, {
|
||||||
}
|
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);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue