This commit is contained in:
Vanessa 2023-02-19 09:24:40 +08:00
parent afdc96458c
commit 1525c6c899
5 changed files with 41 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import {hideMessage, showMessage} from "../dialog/message";
import {confirmDialog} from "../dialog/confirmDialog";
import {hideElements} from "../protyle/ui/hideElements";
import {viewCards} from "./viewCards";
import {Constants} from "../constants";
export const genCardItem = (item: ICardPackage) => {
return `<li data-id="${item.id}" class="b3-list-item b3-list-item--narrow${isMobile() ? "" : " b3-list-item--hide-action"}">
@ -181,7 +182,7 @@ export const quickMakeCard = (nodeElement: Element[]) => {
ids.push(item.getAttribute("data-node-id"));
});
fetchPost("/api/riff/addRiffCards", {
deckID: "20230218211946-2kw8jgx",
deckID: Constants.QUICK_DECK_ID,
blockIDs: ids
});
}

View file

@ -116,7 +116,7 @@ export const viewCards = (deckID: string, title: string, cb:(response:IWebSocket
break;
} else if (type === "remove") {
fetchPost("/api/riff/removeRiffCards", {
deckID: isDoc ? "20230218211946-2kw8jgx" : deckID,
deckID: isDoc ? Constants.QUICK_DECK_ID : deckID,
blockIDs: [target.getAttribute("data-id")]
}, (removeResponse) => {
let nextElment = target.parentElement.nextElementSibling;

View file

@ -85,7 +85,7 @@ export abstract class Constants {
public static readonly TIMEOUT_BLOCKLOAD = 300;
public static readonly TIMEOUT_TRANSITION = 150;
// help path
// id
public static readonly HELP_PATH = {
zh_CN: "20210808180117-czj9bvb",
zh_CHT: "20211226090932-5lcq56f",
@ -93,6 +93,8 @@ export abstract class Constants {
fr_FR: "20210808180117-6v0mkxr",
};
public static readonly QUICK_DECK_ID = "20230218211946-2kw8jgx"
public static readonly KEYCODE: { [key: string]: string[] } = {
"186": [";", ":"],
"187": ["=", "+"],
@ -108,7 +110,8 @@ export abstract class Constants {
};
// 冲突不使用 "⌘S/Q"
// "⌘", "⇧", "⌥", "⌃"
// "⌘A", "⌘X", "⌘C", "⌘V", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌘⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义
// "⌘A", "⌘X", "⌘C", "⌘V", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌘⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←",
// "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义
public static readonly SIYUAN_KEYMAP: IKeymap = {
general: {
editMode: {default: "⇧⌘G", custom: "⇧⌘G"},
@ -159,6 +162,7 @@ export abstract class Constants {
openBy: {default: "⌥,", custom: "⌥,"},
insertRight: {default: "⌥.", custom: "⌥."},
attr: {default: "⌥⌘A", custom: "⌥⌘A"},
quickMakeCard: {default: "⌥⌘F", custom: "⌥⌘F"},
refresh: {default: "F5", custom: "F5"},
copyBlockRef: {default: "⇧⌘C", custom: "⇧⌘C"},
copyProtocol: {default: "⇧⌘H", custom: "⇧⌘H"},

View file

@ -668,7 +668,8 @@ export class Gutter {
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.quickMakeCard,
iconHTML:`<svg class="b3-menu__icon"><use xlink:href="#iconRiffCard"></use></svg>`,
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",
click() {
quickMakeCard(selectsElement);
@ -1440,7 +1441,8 @@ export class Gutter {
if (type !== "NodeThematicBreak") {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.quickMakeCard,
iconHTML:`<svg class="b3-menu__icon"><use xlink:href="#iconRiffCard"></use></svg>`,
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",
click() {
quickMakeCard([nodeElement]);

View file

@ -70,6 +70,7 @@ import {preventScroll} from "../scroll/preventScroll";
import {getSavePath} from "../../util/newFile";
import {escapeHtml} from "../../util/escape";
import {insertHTML} from "../util/insertHTML";
import {quickMakeCard} from "../../card/makeCard";
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
@ -993,6 +994,33 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.quickMakeCard.custom, event)) {
const selectElement: Element[] = []
nodeElement.classList.add("protyle-wysiwyg--select");
let isRemove = true;
const removeIds: string[] = [];
protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => {
selectElement.push(item);
item.classList.remove("protyle-wysiwyg--select");
removeIds.push(item.getAttribute("data-node-id"));
if ((item.getAttribute("custom-riff-decks") || "").indexOf(Constants.QUICK_DECK_ID) > -1) {
isRemove = false;
}
});
if (isRemove) {
fetchPost("/api/riff/removeRiffCards", {
deckID: Constants.QUICK_DECK_ID,
blockIDs: removeIds
}, (removeResponse) => {
});
} else {
quickMakeCard(selectElement);
}
event.preventDefault();
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.attr.custom, event)) {
const topElement = getTopAloneElement(nodeElement);
if (selectText === "") {