mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
enhance(plugins): types
This commit is contained in:
@@ -50,6 +50,7 @@ class LSPluginCaller extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
// run in host
|
||||
async connectToChild() {
|
||||
if (this._connected) return
|
||||
|
||||
@@ -303,7 +304,7 @@ class LSPluginCaller extends EventEmitter {
|
||||
|
||||
this._call = async (...args: any) => {
|
||||
// parent all will get message before handshake
|
||||
await refChild.call(LSPMSGFn(pl.id), {
|
||||
refChild.call(LSPMSGFn(pl.id), {
|
||||
type: args[0],
|
||||
payload: Object.assign(args[1] || {}, {
|
||||
$$pid: pl.id,
|
||||
|
||||
@@ -315,7 +315,7 @@ export type ExternalCommandType =
|
||||
| 'logseq.ui/toggle-theme'
|
||||
| 'logseq.ui/toggle-wide-mode'
|
||||
|
||||
export type UserProxyTags = 'app' | 'editor' | 'db' | 'git' | 'ui' | 'assets' | 'utils'
|
||||
export type UserProxyNSTags = 'app' | 'editor' | 'db' | 'git' | 'ui' | 'assets' | 'utils'
|
||||
|
||||
export type SearchIndiceInitStatus = boolean
|
||||
export type SearchBlockItem = {
|
||||
|
||||
@@ -30,7 +30,7 @@ import {
|
||||
IUserOffHook,
|
||||
IGitProxy,
|
||||
IUIProxy,
|
||||
UserProxyTags,
|
||||
UserProxyNSTags,
|
||||
BlockUUID,
|
||||
BlockEntity,
|
||||
IDatom,
|
||||
@@ -734,7 +734,7 @@ export class LSPluginUser
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_makeUserProxy(target: any, tag?: UserProxyTags) {
|
||||
_makeUserProxy(target: any, nstag?: UserProxyNSTags) {
|
||||
const that = this
|
||||
const caller = this.caller
|
||||
|
||||
@@ -744,13 +744,13 @@ export class LSPluginUser
|
||||
|
||||
return function (this: any, ...args: any) {
|
||||
if (origMethod) {
|
||||
if (args?.length !== 0) args.concat(tag)
|
||||
if (args?.length !== 0) args.concat(nstag)
|
||||
const ret = origMethod.apply(that, args)
|
||||
if (ret !== PROXY_CONTINUE) return ret
|
||||
}
|
||||
|
||||
// Handle hook
|
||||
if (tag) {
|
||||
if (nstag) {
|
||||
const hookMatcher = propKey.toString().match(/^(once|off|on)/i)
|
||||
|
||||
if (hookMatcher != null) {
|
||||
@@ -771,7 +771,7 @@ export class LSPluginUser
|
||||
opts = args[2]
|
||||
}
|
||||
|
||||
type = `hook:${tag}:${safeSnakeCase(type)}`
|
||||
type = `hook:${nstag}:${safeSnakeCase(type)}`
|
||||
|
||||
caller[f](type, handler)
|
||||
|
||||
@@ -796,13 +796,13 @@ export class LSPluginUser
|
||||
let method = propKey as string
|
||||
|
||||
// TODO: refactor api call with the explicit tag
|
||||
if ((['git', 'ui', 'assets', 'utils'] as UserProxyTags[]).includes(tag)) {
|
||||
method = tag + '_' + method
|
||||
if ((['git', 'ui', 'assets', 'utils'] as UserProxyNSTags[]).includes(nstag)) {
|
||||
method = nstag + '_' + method
|
||||
}
|
||||
|
||||
// Call host
|
||||
return caller.callAsync(`api:call`, {
|
||||
tag,
|
||||
tag: nstag,
|
||||
method,
|
||||
args: args,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user