mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
1d31b9a797
commit
999081b573
2 changed files with 41 additions and 0 deletions
32
app/src/plugin/customBlockRender.ts
Normal file
32
app/src/plugin/customBlockRender.ts
Normal 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");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -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[] = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue