🎨 点击快速制卡可进行移除

This commit is contained in:
Vanessa 2023-02-21 13:44:42 +08:00
parent a106b9fe5f
commit ce50681a29
2 changed files with 17 additions and 20 deletions

View file

@ -174,17 +174,29 @@ export const makeCard = (nodeElement: Element[]) => {
};
export const quickMakeCard = (nodeElement: Element[]) => {
let isRemove = true;
const ids: string[] = [];
nodeElement.forEach(item => {
if (item.getAttribute("data-type") === "NodeThematicBreak") {
return;
}
item.classList.remove("protyle-wysiwyg--select");
ids.push(item.getAttribute("data-node-id"));
if ((item.getAttribute("custom-riff-decks") || "").indexOf(Constants.QUICK_DECK_ID) === -1) {
isRemove = false;
}
});
fetchPost("/api/riff/addRiffCards", {
deckID: Constants.QUICK_DECK_ID,
blockIDs: ids
});
if (isRemove) {
fetchPost("/api/riff/removeRiffCards", {
deckID: Constants.QUICK_DECK_ID,
blockIDs: ids
});
} else {
fetchPost("/api/riff/addRiffCards", {
deckID: Constants.QUICK_DECK_ID,
blockIDs: ids
});
}
};

View file

@ -999,25 +999,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (!hasClosestByClassName(nodeElement, "protyle-wysiwyg--select")) {
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
});
} else {
quickMakeCard(selectElement);
}
quickMakeCard(selectElement);
event.preventDefault();
event.stopPropagation();
return true;