diff --git a/app/src/plugin/customBlockRender.ts b/app/src/plugin/customBlockRender.ts new file mode 100644 index 000000000..0ae114922 --- /dev/null +++ b/app/src/plugin/customBlockRender.ts @@ -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", '
'); + } + if (e.childElementCount < 4) { + e.lastElementChild.insertAdjacentHTML("beforebegin", `${Constants.ZWSP}`); + } + const renderElement = e.firstElementChild.nextElementSibling as HTMLElement; + + renderElement.setAttribute("contenteditable", "false"); + e.setAttribute("data-render", "true"); + }); + } +}; diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts index 48380d45b..cbf2fe2f0 100644 --- a/app/src/plugin/index.ts +++ b/app/src/plugin/index.ts @@ -17,6 +17,15 @@ export class Plugin { public eventBus: EventBus; public data: any = {}; 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 setting: Setting; public statusBarIcons: Element[] = [];