This commit is contained in:
Vanessa 2022-12-22 22:19:04 +08:00
parent 26e6b23887
commit 62d975a1e9
7 changed files with 67 additions and 67 deletions

View file

@ -32,11 +32,11 @@ export const pdfResize = () => {
if (!pdfDocument) {
return;
}
const pdfViewerElement = item.element.querySelector("#viewerContainer")
const pdfViewerElement = item.element.querySelector("#viewerContainer");
if (pdfViewerElement) {
// https://github.com/siyuan-note/siyuan/issues/6890
pdfViewerElement.scrollTo(0, parseInt(pdfViewerElement.getAttribute("data-scrolltop")));
pdfViewerElement.removeAttribute("data-scrolltop")
pdfViewerElement.removeAttribute("data-scrolltop");
}
const currentScaleValue = pdfViewer.currentScaleValue;
if (

View file

@ -13,20 +13,20 @@ const genCardItem = (item: { id: string, name: string }) => {
<span data-type="remove" class="b3-list-item__action b3-tooltips b3-tooltips__w" aria-label="${window.siyuan.languages.removeDeck}">
<svg><use xlink:href="#iconMin"></use></svg>
</span>
</li>`
}
</li>`;
};
export const makeCard = (nodeElement: Element[]) => {
const range = getEditorRange(nodeElement[0]);
fetchPost("/api/riff/getRiffDecks", {}, (response) => {
let html = ''
const ids: string[] = []
let html = "";
const ids: string[] = [];
nodeElement.forEach(item => {
ids.push(item.getAttribute("data-node-id"))
})
ids.push(item.getAttribute("data-node-id"));
});
response.data.forEach((item: { id: string, name: string }) => {
html += genCardItem(item)
})
html += genCardItem(item);
});
const dialog = new Dialog({
width: isMobile() ? "80vw" : "50vw",
height: "70vh",
@ -52,18 +52,18 @@ export const makeCard = (nodeElement: Element[]) => {
while (target && !target.isSameNode(dialog.element)) {
const type = target.getAttribute("data-type");
if (type === "create") {
let msgId = ""
let msgId = "";
const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement;
if (inputElement.value) {
if (msgId) {
hideMessage(msgId);
}
fetchPost("/api/riff/createRiffDeck", {name: inputElement.value}, (response) => {
dialog.element.querySelector(".b3-list").insertAdjacentHTML("afterbegin", genCardItem(response.data))
inputElement.value = '';
})
dialog.element.querySelector(".b3-list").insertAdjacentHTML("afterbegin", genCardItem(response.data));
inputElement.value = "";
});
} else {
msgId = showMessage(window.siyuan.languages._kernel[142])
msgId = showMessage(window.siyuan.languages._kernel[142]);
}
event.stopPropagation();
event.preventDefault();
@ -73,8 +73,8 @@ export const makeCard = (nodeElement: Element[]) => {
deckID: target.parentElement.getAttribute("data-id"),
blockIDs: ids
}, () => {
showMessage(window.siyuan.languages.addDeck)
})
showMessage(window.siyuan.languages.addDeck);
});
event.stopPropagation();
event.preventDefault();
break;
@ -83,14 +83,14 @@ export const makeCard = (nodeElement: Element[]) => {
deckID: target.parentElement.getAttribute("data-id"),
blockIDs: ids
}, () => {
showMessage(window.siyuan.languages.removeDeck)
})
showMessage(window.siyuan.languages.removeDeck);
});
event.stopPropagation();
event.preventDefault();
break;
}
target = target.parentElement;
}
})
})
});
});
};

View file

@ -11,13 +11,13 @@ export const openCard = () => {
fetchPost("/api/riff/getRiffDecks", {}, (response) => {
response.data.forEach((deck: { id: string, name: string }) => {
decksHTML += `<option value="${deck.id}">${deck.name}</option>`;
})
});
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
let blocks = cardsResponse.data;
let countHTML = ''
let index = 0
let countHTML = "";
let index = 0;
if (blocks.length > 0) {
countHTML = `<span>1</span>/${blocks.length}`
countHTML = `<span>1</span>/${blocks.length}`;
}
const dialog = new Dialog({
title: window.siyuan.languages.riffCard,
@ -43,7 +43,7 @@ export const openCard = () => {
</div>`,
width: isMobile() ? "80vw" : "50vw",
height: "70vh",
})
});
dialog.element.querySelector("input").focus();
const editor = new Protyle(dialog.element.querySelector("[data-type='render']") as HTMLElement, {
blockId: "",
@ -64,48 +64,48 @@ export const openCard = () => {
onGet(response, editor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]);
});
}
dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom)
const countElement = dialog.element.querySelector('[data-type="count"]')
const actionElement = dialog.element.querySelector('[data-type="action"]')
const selectElement = dialog.element.querySelector("select")
selectElement.addEventListener("change", (event) => {
dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom);
const countElement = dialog.element.querySelector('[data-type="count"]');
const actionElement = dialog.element.querySelector('[data-type="action"]');
const selectElement = dialog.element.querySelector("select");
selectElement.addEventListener("change", () => {
fetchPost("/api/riff/getRiffDueCards", {deckID: selectElement.value}, (cardsChangeResponse) => {
blocks = cardsChangeResponse.data;
index = 0
index = 0;
if (blocks.length > 0) {
countElement.innerHTML = `<span>1</span>/${blocks.length}`
countElement.classList.remove("fn__none")
editor.protyle.element.classList.remove("fn__none")
editor.protyle.element.nextElementSibling.classList.add("fn__none")
actionElement.classList.remove("fn__none")
countElement.innerHTML = `<span>1</span>/${blocks.length}`;
countElement.classList.remove("fn__none");
editor.protyle.element.classList.remove("fn__none");
editor.protyle.element.nextElementSibling.classList.add("fn__none");
actionElement.classList.remove("fn__none");
fetchPost("/api/riff/renderRiffCard", {blockID: blocks[index].blockID}, (response) => {
onGet(response, editor.protyle, [Constants.CB_GET_HISTORY, 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")
actionElement.classList.add("fn__none")
countElement.classList.add("fn__none");
editor.protyle.element.classList.add("fn__none");
editor.protyle.element.nextElementSibling.classList.remove("fn__none");
actionElement.classList.add("fn__none");
}
})
})
});
});
dialog.element.addEventListener("click", (event) => {
let type = ""
let type = "";
if (typeof event.detail === "string") {
if (event.detail === "a") {
type = "0"
type = "0";
} else if (event.detail === "h") {
type = "1"
type = "1";
} else if (event.detail === "g") {
type = "2"
type = "2";
} else if (event.detail === "e") {
type = "3"
type = "3";
} else if (event.detail === "s") {
type = "-1"
type = "-1";
}
}
if (!type) {
const buttonElement = hasClosestByClassName(event.target as HTMLElement, "b3-button")
const buttonElement = hasClosestByClassName(event.target as HTMLElement, "b3-button");
if (buttonElement) {
type = buttonElement.getAttribute("data-type");
}
@ -125,21 +125,21 @@ export const openCard = () => {
blockID: blocks[index].blockID,
rating: parseInt(type)
}, () => {
index++
index++;
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")
actionElement.classList.add("fn__none")
countElement.classList.add("fn__none");
editor.protyle.element.classList.add("fn__none");
editor.protyle.element.nextElementSibling.classList.remove("fn__none");
actionElement.classList.add("fn__none");
return;
}
countElement.firstElementChild.innerHTML = (index + 1).toString()
countElement.firstElementChild.innerHTML = (index + 1).toString();
fetchPost("/api/riff/renderRiffCard", {blockID: blocks[index].blockID}, (response) => {
onGet(response, editor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]);
});
})
});
}
})
})
})
}
});
});
});
};

View file

@ -66,7 +66,7 @@ const renderCompare = (element: HTMLElement) => {
fetchPost("/api/repo/openRepoSnapshotDoc", {id: element.getAttribute("data-id")}, (response) => {
leftElement.classList.remove("fn__none");
const textElement = (leftElement.firstElementChild.nextElementSibling as HTMLTextAreaElement)
const textElement = (leftElement.firstElementChild.nextElementSibling as HTMLTextAreaElement);
if (response.data.isLargeDoc) {
textElement.value = response.data.content;
textElement.classList.remove("fn__none");
@ -81,7 +81,7 @@ const renderCompare = (element: HTMLElement) => {
if (id2) {
rightElement.classList.remove("fn__none");
fetchPost("/api/repo/openRepoSnapshotDoc", {id: id2}, (response) => {
const textElement = (rightElement.firstElementChild.nextElementSibling as HTMLTextAreaElement)
const textElement = (rightElement.firstElementChild.nextElementSibling as HTMLTextAreaElement);
if (response.data.isLargeDoc) {
textElement.value = response.data.content;
textElement.classList.remove("fn__none");

View file

@ -282,9 +282,9 @@ export class Wnd {
const oldTab = getInstanceById(tabId) as Tab;
if (oldTab.model instanceof Asset) {
// https://github.com/siyuan-note/siyuan/issues/6890
const pdfViewerElement = oldTab.model.element.querySelector("#viewerContainer")
const pdfViewerElement = oldTab.model.element.querySelector("#viewerContainer");
if (pdfViewerElement) {
pdfViewerElement.setAttribute("data-scrolltop", pdfViewerElement.scrollTop.toString())
pdfViewerElement.setAttribute("data-scrolltop", pdfViewerElement.scrollTop.toString());
}
}
if (dragElement.style.height === "50%" || dragElement.style.width === "50%") {

View file

@ -916,7 +916,7 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
inputEvent(element, config, undefined, edit);
localStorage.setItem(Constants.LOCAL_SEARCHEDATA, JSON.stringify(config));
window.siyuan.menus.menu.remove();
}
};
const addConfigFilterMenu = (config: ISearchOption, edit: Protyle, element: Element) => {
const filterDialog = new Dialog({

View file

@ -539,7 +539,7 @@ export const globalShortcut = () => {
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.riffCard.custom, event)) {
openCard()
openCard();
event.preventDefault();
return;
}