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