Vanessa 2023-06-05 19:49:32 +08:00
parent 1d31b9a797
commit 999081b573
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,32 @@
import {App} from "../index";
export const customBlockRender = (app: App, element: Element) => {
// TODO
let abcElements: Element[] = [];
if (element.getAttribute("data-subtype") === "abc") {
// 编辑器内代码块编辑渲染
abcElements = [element];
} else {
abcElements = Array.from(element.querySelectorAll('[data-subtype="abc"]'));
}
if (abcElements.length === 0) {
return;
}
if (abcElements.length > 0) {
abcElements.forEach((e: HTMLDivElement) => {
if (e.getAttribute("data-render") === "true") {
return;
}
if (!e.firstElementChild.classList.contains("protyle-icons")) {
e.insertAdjacentHTML("afterbegin", '<div class="protyle-icons"><span class="protyle-icon protyle-icon--first protyle-action__edit"><svg><use xlink:href="#iconEdit"></use></svg></span><span class="protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span></div>');
}
if (e.childElementCount < 4) {
e.lastElementChild.insertAdjacentHTML("beforebegin", `<span style="position: absolute">${Constants.ZWSP}</span>`);
}
const renderElement = e.firstElementChild.nextElementSibling as HTMLElement;
renderElement.setAttribute("contenteditable", "false");
e.setAttribute("data-render", "true");
});
}
};

View file

@ -17,6 +17,15 @@ export class Plugin {
public eventBus: EventBus; public eventBus: EventBus;
public data: any = {}; public data: any = {};
public name: string; public name: string;
// TODO
public customBlockRenders: {
[key: string]: {
icon: string,
action: "edit" | "more"[],
genCursor: boolean,
render: (options: { app: App, element: Element }) => void
}
} = {};
public topBarIcons: Element[] = []; public topBarIcons: Element[] = [];
public setting: Setting; public setting: Setting;
public statusBarIcons: Element[] = []; public statusBarIcons: Element[] = [];