enhance(plugin): support custom routes from the plugin sdk

This commit is contained in:
charlie
2024-03-21 19:07:16 +08:00
parent bd26d0db0e
commit 53125d6315
11 changed files with 124 additions and 50 deletions

View File

@@ -44,7 +44,7 @@ export class LSPluginExperiments {
}
registerFencedCodeRenderer(
type: string,
lang: string,
opts: {
edit?: boolean
before?: () => Promise<void>
@@ -54,7 +54,23 @@ export class LSPluginExperiments {
) {
return this.ensureHostScope().logseq.api.exper_register_fenced_code_renderer(
this.ctx.baseInfo.id,
type,
lang,
opts
)
}
registerRouteRenderer(
key: string,
opts: {
name?: string,
path: string,
render: (props: { content: string }) => any
subs?: Array<string>
}
) {
return this.ensureHostScope().logseq.api.exper_register_route_renderer(
this.ctx.baseInfo.id,
key,
opts
)
}
@@ -83,7 +99,8 @@ export class LSPluginExperiments {
ensureHostScope(): any {
if (window === top) {
throw new Error('Can not access host scope!')
console.error('Can not access host scope!')
return {}
}
return top