This commit is contained in:
Vanessa 2022-08-18 23:47:22 +08:00
parent c29b2404ea
commit 17a8d4fac2
4 changed files with 12 additions and 9 deletions

View file

@ -1041,14 +1041,14 @@ export class Toolbar {
</div>`;
const listElement = this.subElement.querySelector(".b3-list");
const previewElement = this.subElement.firstElementChild.lastElementChild;
previewTemplate(listElement.firstElementChild.getAttribute("data-value"), previewElement, protyle.block.parentID)
previewTemplate(listElement.firstElementChild.getAttribute("data-value"), previewElement, protyle.block.parentID);
listElement.addEventListener("mouseover", (event) => {
const target = event.target as HTMLElement;
const hoverItemElement = hasClosestByClassName(target, "b3-list-item");
if (!hoverItemElement) {
return;
}
previewTemplate(hoverItemElement.getAttribute("data-value"), previewElement, protyle.block.parentID)
previewTemplate(hoverItemElement.getAttribute("data-value"), previewElement, protyle.block.parentID);
});
const inputElement = this.subElement.querySelector("input");
inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
@ -1056,11 +1056,11 @@ export class Toolbar {
if (event.isComposing) {
return;
}
const isEmpty = !this.subElement.querySelector(".b3-list-item")
const isEmpty = !this.subElement.querySelector(".b3-list-item");
if (!isEmpty) {
const currentElement = upDownHint(listElement, event);
if (currentElement) {
previewTemplate(currentElement.getAttribute("data-value"), previewElement, protyle.block.parentID)
previewTemplate(currentElement.getAttribute("data-value"), previewElement, protyle.block.parentID);
}
}
if (event.key === "Enter") {
@ -1207,7 +1207,7 @@ export class Toolbar {
if (event.isComposing) {
return;
}
const isEmpty = !this.subElement.querySelector(".b3-list-item")
const isEmpty = !this.subElement.querySelector(".b3-list-item");
if (!isEmpty) {
const currentElement = upDownHint(listElement, event);
if (currentElement) {

View file

@ -2,7 +2,7 @@ import {fetchPost} from "../../util/fetch";
export const previewTemplate = (pathString: string, element: Element, parentId: string) => {
if (!pathString) {
element.innerHTML = ""
element.innerHTML = "";
return;
}
fetchPost("/api/template/render", {
@ -10,5 +10,5 @@ export const previewTemplate = (pathString: string, element: Element, parentId:
path: pathString
}, (response) => {
element.innerHTML = `<div class="protyle-wysiwyg" style="padding: 8px">${response.data.content.replace(/contenteditable="true"/g, "")}</div>`;
})
}
});
};