mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 17:06:23 +00:00
feat(plugin): support configurable UI api for toolbar action items
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
invokeHostExportedApi,
|
||||
isObject, withFileProtocol
|
||||
} from './helpers'
|
||||
import * as pluginHelpers from './helpers'
|
||||
import Debug from 'debug'
|
||||
import {
|
||||
LSPluginCaller,
|
||||
@@ -905,7 +906,7 @@ class LSPluginCore
|
||||
|
||||
this.emit('beforeenable')
|
||||
p.settings?.set('disabled', false)
|
||||
// this.emit('enabled', p)
|
||||
this.emit('enabled', p.id)
|
||||
}
|
||||
|
||||
async disable (plugin: PluginLocalIdentity) {
|
||||
@@ -914,7 +915,7 @@ class LSPluginCore
|
||||
|
||||
this.emit('beforedisable')
|
||||
p.settings?.set('disabled', true)
|
||||
// this.emit('disabled', p)
|
||||
this.emit('disabled', p.id)
|
||||
}
|
||||
|
||||
async _hook (ns: string, type: string, payload?: any, pid?: string) {
|
||||
@@ -1019,5 +1020,6 @@ function setupPluginCore (options: any) {
|
||||
|
||||
export {
|
||||
PluginLocal,
|
||||
pluginHelpers,
|
||||
setupPluginCore
|
||||
}
|
||||
|
||||
@@ -183,6 +183,11 @@ export interface IAppProxy {
|
||||
showMsg: (content: string, status?: 'success' | 'warning' | string) => void
|
||||
setZoomFactor: (factor: number) => void
|
||||
|
||||
registerUIItem: (
|
||||
type: 'toolbar' | 'page',
|
||||
opts: { key: string, template: string }
|
||||
) => boolean
|
||||
|
||||
// events
|
||||
onCurrentGraphChanged: IUserHook
|
||||
onThemeModeChanged: IUserHook<{ mode: 'dark' | 'light' }>
|
||||
|
||||
@@ -25,7 +25,22 @@ declare global {
|
||||
|
||||
const debug = Debug('LSPlugin:user')
|
||||
|
||||
const app: Partial<IAppProxy> = {}
|
||||
const app: Partial<IAppProxy> = {
|
||||
registerUIItem (
|
||||
type: 'toolbar' | 'page',
|
||||
opts: { key: string, template: string }
|
||||
) {
|
||||
const pid = this.baseInfo.id
|
||||
// opts.key = `${pid}_${opts.key}`
|
||||
|
||||
this.caller?.call(`api:call`, {
|
||||
method: 'register-plugin-ui-item',
|
||||
args: [pid, type, opts]
|
||||
})
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
let registeredCmdUid = 0
|
||||
|
||||
@@ -101,7 +116,7 @@ const editor: Partial<IEditorProxy> = {
|
||||
args: [this.baseInfo.id, [{ key, label, type }, ['editor/hook', eventKey]]]
|
||||
})
|
||||
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user