mirror of
https://github.com/logseq/logseq.git
synced 2026-05-25 13:14:39 +00:00
Added
1. All configurations of current graph.
App.getCurrentGraphConfigs: () => Promise<any>
2. All favorite pages list of current graph.
App.getCurrentGraphFavorites: () => Promise<Array<string> | null>
3. All recent pages list of current graph.
App.getCurrentGraphRecent: () => Promise<Array<string> | null>
4. Clear right sidebar blocks.
App.clearRightSidebarBlocks: (opts?: { close: boolean }) => void
5. Support register CodeMirror enhancer. #Experiment feature
Experiments.registerExtensionsEnhancer<T = any>(type: 'katex' | 'codemirror', enhancer: (v: T) => Promise<any>)
6. Support hooks for app search service. #Alpha stage
App.registerSearchService<T extends IPluginSearchServiceHooks>(s: T): void
7. Support focus option for App.insertBlock. Credit to [[tennox]] #PR
Fixed
1. Adjust build script to be compatible for shadow-cljs bundler.
How to set up a clojurescript project with shadow-cljs?
https://github.com/rlhk/logseq-url-plus/blob/main/doc/dev-notes.md
91 lines
2.1 KiB
TypeScript
91 lines
2.1 KiB
TypeScript
import { LSPluginUser } from '../LSPlugin.user'
|
|
import { PluginLocal } from '../LSPlugin.core'
|
|
import { safeSnakeCase } from '../helpers'
|
|
|
|
/**
|
|
* WARN: These are some experience features and may be adjusted at any time.
|
|
* These unofficial plugins that use these APIs are temporarily
|
|
* not supported on the Marketplace.
|
|
*/
|
|
export class LSPluginExperiments {
|
|
constructor(private ctx: LSPluginUser) {}
|
|
|
|
get React(): unknown {
|
|
return this.ensureHostScope().React
|
|
}
|
|
|
|
get ReactDOM(): unknown {
|
|
return this.ensureHostScope().ReactDOM
|
|
}
|
|
|
|
get pluginLocal(): PluginLocal {
|
|
return this.ensureHostScope().LSPluginCore.ensurePlugin(
|
|
this.ctx.baseInfo.id
|
|
)
|
|
}
|
|
|
|
public invokeExperMethod(type: string, ...args: Array<any>) {
|
|
const host = this.ensureHostScope()
|
|
type = safeSnakeCase(type)?.toLowerCase()
|
|
return host.logseq.api['exper_' + type]?.apply(host, args)
|
|
}
|
|
|
|
async loadScripts(...scripts: Array<string>) {
|
|
scripts = scripts.map((it) => {
|
|
if (!it?.startsWith('http')) {
|
|
return this.ctx.resolveResourceFullUrl(it)
|
|
}
|
|
|
|
return it
|
|
})
|
|
|
|
scripts.unshift(this.ctx.baseInfo.id)
|
|
await this.invokeExperMethod('loadScripts', ...scripts)
|
|
}
|
|
|
|
registerFencedCodeRenderer(
|
|
type: string,
|
|
opts: {
|
|
edit?: boolean
|
|
before?: () => Promise<void>
|
|
subs?: Array<string>
|
|
render: (props: { content: string }) => any
|
|
}
|
|
) {
|
|
return this.ensureHostScope().logseq.api.exper_register_fenced_code_renderer(
|
|
this.ctx.baseInfo.id,
|
|
type,
|
|
opts
|
|
)
|
|
}
|
|
|
|
registerExtensionsEnhancer<T = any>(
|
|
type: 'katex' | 'codemirror',
|
|
enhancer: (v: T) => Promise<any>
|
|
) {
|
|
const host = this.ensureHostScope()
|
|
|
|
switch (type) {
|
|
case 'katex':
|
|
if (host.katex) {
|
|
enhancer(host.katex).catch(console.error)
|
|
}
|
|
break
|
|
default:
|
|
}
|
|
|
|
return host.logseq.api.exper_register_extensions_enhancer(
|
|
this.ctx.baseInfo.id,
|
|
type, enhancer
|
|
)
|
|
}
|
|
|
|
ensureHostScope(): any {
|
|
if (window === top) {
|
|
throw new Error('Can not access host scope!')
|
|
}
|
|
|
|
return top
|
|
}
|
|
}
|