1
0
silverbullet/web/cm_plugins/top_bottom_panels.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Decoration, EditorState, WidgetType } from "../deps.ts";
import type { Client } from "../client.ts";
import { decoratorStateField } from "./util.ts";
import { MarkdownWidget } from "./markdown_widget.ts";
export function postScriptPrefacePlugin(
editor: Client,
) {
const panelWidgetHook = editor.system.panelWidgetHook;
return decoratorStateField((state: EditorState) => {
const widgets: any[] = [];
const topCallback = panelWidgetHook.callbacks.get("top");
if (topCallback) {
2023-11-25 12:40:56 +00:00
widgets.push(
Decoration.widget({
widget: new MarkdownWidget(
undefined,
2023-11-25 12:40:56 +00:00
editor,
`top:${editor.currentPage}`,
topCallback,
"sb-markdown-top-widget",
2023-11-25 12:40:56 +00:00
),
side: -1,
block: true,
}).range(0),
);
}
const bottomCallback = panelWidgetHook.callbacks.get("bottom");
if (bottomCallback) {
widgets.push(
Decoration.widget({
widget: new MarkdownWidget(
undefined,
editor,
`bottom:${editor.currentPage}`,
bottomCallback,
"sb-markdown-bottom-widget",
),
side: 1,
block: true,
}).range(state.doc.length),
);
}
return Decoration.set(widgets);
});
}