### Example of provideStyle Usage in Logseq Plugin
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Demonstrates how to use `logseq.provideStyle` to inject a custom CSS import statement into the Logseq app. This example imports a font stylesheet from a CDN.
```JavaScript
logseq.provideStyle(`
@import url("https://at.alicdn.com/t/font_2409735_r7em724douf.css");
`)
```
--------------------------------
### Install Logseq SDK Libraries with Yarn
Source: https://logseq.github.io/plugins/index
This snippet demonstrates how to add the `@logseq/libs` package to your project using the Yarn package manager, making the Logseq SDK available for development.
```shell
yarn add @logseq/libs
```
--------------------------------
### Display a Message using Logseq UI
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Demonstrates how to display a simple message using the Logseq UI API. This is a basic example of interacting with the Logseq environment from a plugin.
```TypeScript
logseq.UI.showMsg('Hello, Logseq')
```
--------------------------------
### Inject Custom UI with Logseq provideUI
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Demonstrates how to use `logseq.provideUI` to inject a custom UI element, specifically an interactive link with an icon, into the Logseq application at a specified DOM path ('#search'). The example includes an `onclick` handler for basic interaction.
```JavaScript
logseq.provideUI({
key: 'open-calendar',
path: '#search',
template: `
`
})
```
--------------------------------
### Get LSPluginBaseInfo Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Retrieves the plugin configurations from package.json, returning an LSPluginBaseInfo object.
```APIDOC
get baseInfo(): LSPluginBaseInfo
Description: The plugin configurations from package.json
Returns: LSPluginBaseInfo
Source: src/LSPlugin.user.ts:683
```
--------------------------------
### Example of provideModel Usage in Logseq Plugin
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Demonstrates how to use `logseq.provideModel` to expose a custom function `openCalendar` that can be called from the Logseq UI. This function will log a message to the console when invoked.
```JavaScript
logseq.provideModel({
openCalendar () {
console.log('Open the calendar!')
}
})
```
--------------------------------
### Get Application Info (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves information about the Logseq application. An optional key can be provided to get a specific piece of information from the AppInfo type. Returns a Promise that resolves to any type, depending on the key. This method was added in version 0.0.4.
```APIDOC
getInfo:
Signature: ((key?: keyof AppInfo) => Promise)
Parameters:
Optional key: keyof AppInfo
Returns: Promise
Added: 0.0.4
```
--------------------------------
### Get State From App Store (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves a value from the Logseq application's state store. The path can be a string or an array of strings to navigate the state tree. This method is generic, allowing specification of the return type `T`. Refer to the provided URL for valid state paths. An example demonstrates how to check if Logseq is in document mode.
```APIDOC
getStateFromStore:
Signature: ((path: string | string[]) => Promise)
Description: Get state from app store
Type Parameters:
T = any
Parameters:
path: string | string[]
Returns: Promise
```
```JavaScript
const isDocMode = await logseq.App.getStateFromStore('document/mode?')
```
--------------------------------
### Get User Configurations (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves the current user configurations for the Logseq application. Returns a Promise that resolves to an AppUserConfigs object.
```APIDOC
getUserConfigs:
Signature: (() => Promise)
Returns: Promise
```
--------------------------------
### Set Main UI Inline Style with Logseq
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Illustrates how to apply inline CSS styles to the main plugin UI container using `logseq.setMainUIInlineStyle`. The example sets the `position` to 'fixed' and `zIndex` to '11', useful for overlaying UI elements.
```JavaScript
logseq.setMainUIInlineStyle({
position: 'fixed',
zIndex: 11
})
```
--------------------------------
### API Reference: ready Function
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Documents the `ready` function, which signifies that the main Logseq application is fully initialized and ready for the plugin to begin its operations. It can optionally accept a model and a callback.
```APIDOC
ready(model?: any, callback?: any): Promise
model?: any - Optional model, same as the model in `provideModel`.
callback?: any - Optional callback function.
Returns: Promise - A promise that resolves when the plugin is ready.
```
--------------------------------
### Define setupPluginUserInstance Function API
Source: https://logseq.github.io/plugins/functions/setupPluginUserInstance
Documents the `setupPluginUserInstance` function, an internal utility for initializing a Logseq plugin user instance. It requires base plugin information (`LSPluginBaseInfo`) and a caller instance (`LSPluginCaller`), returning a `LSPluginUser` object.
```APIDOC
Function: setupPluginUserInstance
Description: Internal function to set up a Logseq plugin user instance.
Signature: setupPluginUserInstance(pluginBaseInfo: LSPluginBaseInfo, pluginCaller: LSPluginCaller): LSPluginUser
Parameters:
- pluginBaseInfo: LSPluginBaseInfo - Base information for the plugin.
- pluginCaller: LSPluginCaller - The caller instance for the plugin.
Returns: LSPluginUser - An instance of the LSPluginUser.
Defined in: src/LSPlugin.user.ts:846
```
--------------------------------
### API: setBlockCollapsed Method and Example
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
API documentation for the `setBlockCollapsed` method, which asynchronously sets or toggles the collapsed state of a block identified by its UUID. Includes a JavaScript example demonstrating its usage.
```APIDOC
setBlockCollapsed:
Signature: (uuid: string, opts: boolean | "toggle" | { flag: boolean | "toggle"; }): Promise
Parameters:
uuid: string
opts: boolean | "toggle" | { flag: boolean | "toggle"; }
Returns: Promise
```
```JavaScript
logseq.Editor.setBlockCollapsed('uuid', true)
logseq.Editor.setBlockCollapsed('uuid', 'toggle')
```
--------------------------------
### Logseq Plugin API Modules, Interfaces, and Functions Overview
Source: https://logseq.github.io/plugins/types/SlashCommandActionCmd
A comprehensive listing of the key modules, interfaces, and functions exposed by the `@logseq/libs` library. This overview helps developers understand the available building blocks for creating robust Logseq plugins, covering application data, UI elements, database interactions, and more.
```APIDOC
@logseq/libs:
Modules:
- LSPluginUser
- AppGraphInfo
- AppInfo
- AppUserConfigs
- AppUserInfo
- BlockEntity
- IAppProxy
- IAssetsProxy
- IDBProxy
- IEditorProxy
- IGitProxy
- ILSPluginThemeManager
- ILSPluginUser
- IPluginSearchServiceHooks
- IUIProxy
- LSPluginBaseInfo
- LSPluginPkgConfig
- LegacyTheme
- PageEntity
- Theme
- BlockCommandCallback
- BlockCursorPosition
- BlockIdentity
- BlockPageName
- BlockUUID
- BlockUUIDTuple
- EntityID
- ExternalCommandType
- IBatchBlock
- IDatom
- IEntityID
- IGitResult
- IHookEvent
- IUserConditionSlotHook
- IUserHook
- IUserOffHook
- IUserSlotHook
- LSPluginUserEvents
- PageIdentity
- PluginLocalIdentity
- SearchBlockItem
- SearchFileItem
- SearchIndiceInitStatus
- SearchPageItem
- SettingSchemaDesc
- SimpleCommandCallback
- SimpleCommandKeybinding
- SlashCommandAction
- SlashCommandActionCmd
- StyleOptions
- StyleString
- ThemeMode
- UIBaseOptions
- UIContainerAttrs
- UIMsgKey
- UIMsgOptions
- UIOptions
- UIPathIdentity
- UIPathOptions
- UISlotIdentity
- UISlotOptions
- UserProxyTags
- WithOptional
Functions:
- setupPluginUserInstance
```
--------------------------------
### Get Plugin Version Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Retrieves the plugin version string.
```APIDOC
get version(): string
Returns: string
Source: src/LSPlugin.user.ts:670
```
--------------------------------
### IAssetsProxy Interface API Reference
Source: https://logseq.github.io/plugins/interfaces/IAssetsProxy
Detailed API documentation for the IAssetsProxy interface, outlining its methods for asset management within Logseq, such as listing files and creating sandbox storage.
```APIDOC
Interface IAssetsProxy:
Description: Assets related APIs
Hierarchy: IAssetsProxy
Defined in: src/LSPlugin.ts:878
Methods:
listFilesOfCurrentGraph:
Signature: listFilesOfCurrentGraph(exts?: string | string[]): Promise<{
accessTime: number;
birthTime: number;
changeTime: number;
modifiedTime: number;
path: string;
size: number;
}[]>
Description: Lists files of the current graph.
Added: 0.0.2
Parameters:
exts:
Type: string | string[]
Optional: true
Description: Optional file extensions to filter the list by.
Returns: Promise<{
accessTime: number;
birthTime: number;
changeTime: number;
modifiedTime: number;
path: string;
size: number;
}[]>
Defined in: src/LSPlugin.ts:883
makeSandboxStorage:
Signature: makeSandboxStorage(): IAsyncStorage
Description: Creates an isolated asynchronous storage instance for sandboxed operations.
Added: 0.0.10
Returns: IAsyncStorage
Defined in: src/LSPlugin.ts:896
Example: https://github.com/logseq/logseq/pull/6488
```
--------------------------------
### Get Effect Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Retrieves the effect status, returning a boolean.
```APIDOC
get effect(): Boolean
Returns: Boolean
Source: src/LSPlugin.user.ts:687
```
--------------------------------
### Get PluginLogger Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Retrieves the plugin logger instance, returning a PluginLogger object.
```APIDOC
get logger(): PluginLogger
Returns: PluginLogger
Source: src/LSPlugin.user.ts:691
```
--------------------------------
### Show Main Plugin UI
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Displays the main user interface of the plugin. Allows for optional auto-focusing.
```APIDOC
showMainUI:
Signature: showMainUI(opts?: { autoFocus: boolean; }): void
Description: show the plugin's UI
Parameters:
opts: Optional object
autoFocus: boolean - If true, automatically focuses the UI.
Returns: void
```
--------------------------------
### Get LSPluginCaller Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Retrieves the duplex message caller, returning an LSPluginCaller object.
```APIDOC
get caller(): LSPluginCaller
Description: Duplex message caller
Returns: LSPluginCaller
Source: src/LSPlugin.user.ts:699
```
--------------------------------
### Show Plugin Settings UI
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Displays the settings user interface for the plugin.
```APIDOC
showSettingsUI:
Signature: showSettingsUI(): void
Description: Displays the plugin's settings UI.
Parameters: None
Returns: void
```
--------------------------------
### Get Main UI Visibility Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Checks if the main UI is visible, returning a boolean.
```APIDOC
get isMainUIVisible(): boolean
Returns: boolean
Source: src/LSPlugin.user.ts:674
```
--------------------------------
### Get Connection Status Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Checks the connection status with the main app, returning a boolean indicating if connected.
```APIDOC
get connected(): boolean
Description: Connection status with the main app
Returns: boolean
Source: src/LSPlugin.user.ts:679
```
--------------------------------
### Show Main UI (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Displays the plugin's main user interface. An optional parameter allows setting focus to the UI upon display.
```APIDOC
showMainUI(opts?: {
autoFocus: boolean;
}): void
Parameters:
opts?: {
autoFocus: boolean;
}
autoFocus: boolean
Returns: void
Defined in src/LSPlugin.ts:1045
```
--------------------------------
### IEditorProxy.createPage Method
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
Creates a new page with the given name, optional properties, and creation options. Returns a Promise that resolves to the created PageEntity.
```APIDOC
Method: createPage
Signature: (pageName: string, properties?: {}, opts?: Partial<{ createFirstBlock: boolean; format: "markdown" | "org"; journal: boolean; redirect: boolean; }>) => Promise
Parameters:
- pageName: string (The name of the page to create.)
- properties?: {} (Optional properties for the new page.)
- opts?: Partial<{ createFirstBlock: boolean; format: "markdown" | "org"; journal: boolean; redirect: boolean; }> (Optional creation options, including whether to create a first block, format, journal status, and redirection.)
Returns: Promise
Defined In: src/LSPlugin.ts:713
```
--------------------------------
### Get Plugin User Settings Property
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Retrieves the plugin user settings, which include a disabled flag and arbitrary key-value pairs.
```APIDOC
get settings(): {
disabled: boolean;
[key: string]: any;
}
Description: The plugin user settings
Returns: { disabled: boolean; [key: string]: any; }
Properties:
disabled: boolean
[key: string]: any
Source: src/LSPlugin.user.ts:695
```
--------------------------------
### Get Event Listeners
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Retrieves an array of all callback functions registered for a given event. This method is inherited from EventEmitter.
```APIDOC
listeners(event: T): ((...args: any[]) => void)[]
Type Parameters:
- T extends LSPluginUserEvents
Parameters:
- event: T
Returns ((...args: any[]) => void)[]
Inherited from EventEmitter.listeners
```
--------------------------------
### Show Settings UI (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Displays the plugin's dedicated settings user interface, allowing users to configure plugin options.
```APIDOC
showSettingsUI(): void
Returns: void
Defined in src/LSPlugin.ts:1022
```
--------------------------------
### Get User Information (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves information about the current user in Logseq. Returns a Promise that resolves to an AppUserInfo object.
```APIDOC
getUserInfo:
Signature: (() => Promise)
Returns: Promise
```
--------------------------------
### LSPluginUser Class API Reference
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Comprehensive API documentation for the `LSPluginUser` class, detailing its constructor, properties, accessors, and methods available for Logseq plugin development. This class serves as the primary interface for user plugins to interact with the Logseq application.
```APIDOC
Class LSPluginUser:
User plugin instance from global namespace `logseq`.
Hierarchy:
EventEmitter
+ LSPluginUser
Implements:
ILSPluginUser
Defined in src/LSPlugin.user.ts:457
Constructors:
constructor(
_baseInfo: LSPluginBaseInfo,
_caller: LSPluginCaller
):
_baseInfo: LSPluginBaseInfo
_caller: LSPluginCaller
Returns: LSPluginUser
Overrides EventEmitter.constructor
Defined in src/LSPlugin.user.ts:486
Properties:
_baseInfo: LSPluginBaseInfo (Private)
Defined in src/LSPlugin.user.ts:487
_beforeunloadCallback?: ((e: any) => Promise) (Private, Optional)
Type declaration:
(e: any): Promise
handler of before unload plugin
Parameters:
e: any
Returns: Promise
Defined in src/LSPlugin.user.ts:480
_caller: LSPluginCaller (Private)
Defined in src/LSPlugin.user.ts:488
_connected: boolean = false (Private)
Defined in src/LSPlugin.user.ts:464
// Other properties listed in Index:
_debugTag
_mExperiments
_mFileStorage
_mRequest
_settingsSchema?
_ui
_version
prefixed
Accessors:
App
Assets
DB
Editor
Experiments
FileStorage
Git
Request
UI
baseInfo
caller
connected
effect
isMainUIVisible
logger
settings
version
Methods:
_callWin
_execCallableAPI
_execCallableAPIAsync
_makeUserProxy
addListener
beforeunload
emit
ensureConnected
eventNames
hideMainUI
hideSettingsUI
listenerCount
listeners
off
on
onSettingsChanged
once
provideModel
provideStyle
provideTheme
provideUI
ready
removeAllListeners
removeListener
resolveResourceFullUrl
setMainUIAttrs
setMainUIInlineStyle
showMainUI
showSettingsUI
toggleMainUI
updateSettings
useSettingsSchema
```
--------------------------------
### Set Application Theme (provideTheme)
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Sets the visual theme for the main Logseq application. This allows plugins to customize the overall appearance of the user interface.
```APIDOC
provideTheme(theme: Theme): ILSPluginUser
Parameters:
theme: Theme
Returns ILSPluginUser
Defined in src/LSPlugin.ts:971
```
--------------------------------
### Logseq Plugin API: Core Modules, Interfaces, and Types
Source: https://logseq.github.io/plugins/types/UIOptions
A comprehensive list of core modules, interfaces, and type aliases exposed by the `@logseq/libs` library. This section serves as a directory for developers to identify available API entities for building Logseq plugins, including application information, block and page entities, editor interactions, and various utility types.
```APIDOC
Modules:
- LSPluginUser
- AppGraphInfo
- AppInfo
- AppUserConfigs
- AppUserInfo
- BlockEntity
- IAppProxy
- IAssetsProxy
- IDBProxy
- IEditorProxy
- IGitProxy
- ILSPluginThemeManager
- ILSPluginUser
- IPluginSearchServiceHooks
- IUIProxy
- LSPluginBaseInfo
- LSPluginPkgConfig
- LegacyTheme
- PageEntity
- Theme
- BlockCommandCallback
- BlockCursorPosition
- BlockIdentity
- BlockPageName
- BlockUUID
- BlockUUIDTuple
- EntityID
- ExternalCommandType
- IBatchBlock
- IDatom
- IEntityID
- IGitResult
- IHookEvent
- IUserConditionSlotHook
- IUserHook
- IUserOffHook
- IUserSlotHook
- LSPluginUserEvents
- PageIdentity
- PluginLocalIdentity
- SearchBlockItem
- SearchFileItem
- SearchIndiceInitStatus
- SearchPageItem
- SettingSchemaDesc
- SimpleCommandCallback
- SimpleCommandKeybinding
- SlashCommandAction
- SlashCommandActionCmd
- StyleOptions
- StyleString
- ThemeMode
- UIBaseOptions
- UIContainerAttrs
- UIMsgKey
- UIMsgOptions
- UIOptions
- UIPathIdentity
- UIPathOptions
- UISlotIdentity
- UISlotOptions
- UserProxyTags
- WithOptional
- setupPluginUserInstance
```
--------------------------------
### API Method: getCurrentPageBlocksTree
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
Retrieves all blocks of the current page as a tree structure. This is useful for processing the page's content programmatically, for example, to build a mind map.
```APIDOC
getCurrentPageBlocksTree(): Promise
Returns: Promise
```
```JavaScript
const blocks = await logseq.Editor.getCurrentPageBlocksTree()
initMindMap(blocks)
```
--------------------------------
### Register Highlight Context Menu Item
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
Registers a custom command for the highlight context menu, currently available only within the PDF viewer. This allows plugins to add actions related to text selections or highlights.
```APIDOC
registerHighlightContextMenuItem(
label: string,
action: SimpleCommandCallback,
opts?: {
clearSelection: boolean;
}
): unknown
Parameters:
label: string
displayed name of command
action: SimpleCommandCallback
callback for the clickable item
opts (Optional): {
clearSelection: boolean;
}
clearSelection: clear highlight selection when callback invoked
clearSelection: boolean
Returns: unknown
```
--------------------------------
### Handle Plugin Ready Event (ready)
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Triggers when the main Logseq application is fully loaded and ready to run the plugin. This method supports various overloads for providing a model or a callback function to execute upon readiness.
```APIDOC
ready(model?: Record): Promise
Parameters:
Optional model: Record
same as the model in `provideModel`
Returns Promise
Defined in src/LSPlugin.ts:940
```
```APIDOC
ready(callback?: ((e: any) => void | {})): Promise
Parameters:
Optional callback: ((e: any) => void | {})
a function to run when the main Logseq app is ready
(e: any): void | {}
Parameters:
e: any
Returns void | {}
Returns Promise
Defined in src/LSPlugin.ts:945
```
```APIDOC
ready(model?: Record, callback?: ((e: any) => void | {})): Promise
Parameters:
Optional model: Record
Optional callback: ((e: any) => void | {})
(e: any): void | {}
Parameters:
e: any
Returns void | {}
Returns Promise
Defined in src/LSPlugin.ts:947
```
--------------------------------
### Use Settings Schema
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Defines and applies a schema for the plugin's settings, which can be used for validation or UI generation. Returns the LSPluginUser instance for chaining.
```APIDOC
useSettingsSchema:
Signature: useSettingsSchema(schema: SettingSchemaDesc[]): LSPluginUser
Description: Applies a settings schema to the plugin.
Parameters:
schema: SettingSchemaDesc[] - An array defining the structure and types of plugin settings.
Returns: LSPluginUser - The plugin user instance.
Example: https://github.com/logseq/logseq-plugin-samples/tree/master/logseq-awesome-fonts
```
--------------------------------
### Get Registered Event Names
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Returns an array listing the events for which the emitter has registered listeners. This method is inherited from EventEmitter and can be useful for debugging or introspection.
```APIDOC
eventNames(): LSPluginUserEvents[]
Returns LSPluginUserEvents[]
Inherited from EventEmitter.eventNames
```
--------------------------------
### provideTheme Method for LSPluginUser
Source: https://logseq.github.io/plugins/classes/LSPluginUser
Sets the theme for the main Logseq application. This allows plugins to apply custom themes, altering the overall visual style of the Logseq interface.
```APIDOC
provideTheme(theme: Theme): LSPluginUser
Parameters:
theme: Theme
Returns: LSPluginUser
Implementation of ILSPluginUser.provideTheme
Defined in src/LSPlugin.user.ts:581
```
--------------------------------
### Get Current Graph Favorites (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves a list of favorite graph paths. Returns a Promise that resolves to an array of strings, where each string is a graph path.
```APIDOC
getCurrentGraphFavorites:
Signature: (() => Promise)
Returns: Promise
```
--------------------------------
### Prepend Block in Page
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
Prepends a new block with specified content and optional properties to the beginning of a given page.
```APIDOC
prependBlockInPage: ((page: PageIdentity, content: string, opts?: Partial<{
properties: {};
}>) => Promise)
```
--------------------------------
### API Method: Get Block Cursor Position Type Declaration
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
Defines the type signature for a function that asynchronously returns the current block cursor position within Logseq.
```APIDOC
Type Declaration: () => Promise
Returns: Promise
```
--------------------------------
### API: Relaunch Application
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Initiates a relaunch of the Logseq application. This asynchronous function returns a Promise that resolves once the relaunch process has completed.
```APIDOC
relaunch(): Promise
Parameters: None
Returns: Promise - A promise that resolves when the application has relaunched.
```
--------------------------------
### Get Current Graph Recent (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves a list of recently accessed graph paths. Returns a Promise that resolves to an array of strings, where each string is a graph path.
```APIDOC
getCurrentGraphRecent:
Signature: (() => Promise)
Returns: Promise
```
--------------------------------
### Input Selection End Hook
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
A user hook that triggers when an input selection ends. It provides detailed information about the selection, including caret position, start and end indices, and the selected text.
```APIDOC
onInputSelectionEnd: IUserHook<{
caret: any;
end: number;
point: {
x: number;
y: number;
};
start: number;
text: string;
}, IUserOffHook>
Example:
https://github.com/logseq/logseq-plugin-samples/tree/master/logseq-a-translator
```
--------------------------------
### Logseq SDK Libraries API Reference
Source: https://logseq.github.io/plugins/index
This section provides a comprehensive reference to the modules, classes, interfaces, and types exposed by the `@logseq/libs` package, detailing the available components for Logseq plugin development.
```APIDOC
Modules:
- @logseq/libs
Classes:
- LSPluginUser
Interfaces:
- AppGraphInfo
- AppInfo
- AppUserConfigs
- AppUserInfo
- BlockEntity
- IAppProxy
- IAssetsProxy
- IDBProxy
- IEditorProxy
- IGitProxy
- ILSPluginThemeManager
- ILSPluginUser
- IPluginSearchServiceHooks
- IUIProxy
- LSPluginBaseInfo
- LSPluginPkgConfig
- LegacyTheme
- PageEntity
- Theme
Types:
- BlockCommandCallback
- BlockCursorPosition
- BlockIdentity
- BlockPageName
- BlockUUID
- BlockUUIDTuple
- EntityID
- ExternalCommandType
- IBatchBlock
- IDatom
- IEntityID
- IGitResult
- IHookEvent
- IUserConditionSlotHook
- IUserHook
- IUserOffHook
- IUserSlotHook
- LSPluginUserEvents
- PageIdentity
- PluginLocalIdentity
- SearchBlockItem
- SearchFileItem
- SearchIndiceInitStatus
- SearchPageItem
- SettingSchemaDesc
- SimpleCommandCallback
- SimpleCommandKeybinding
- SlashCommandAction
- SlashCommandActionCmd
- StyleOptions
- StyleString
- ThemeMode
- UIBaseOptions
- UIContainerAttrs
- UIMsgKey
- UIMsgOptions
- UIOptions
- UIPathIdentity
- UIPathOptions
- UISlotIdentity
- UISlotOptions
- UserProxyTags
- WithOptional
Functions:
- setupPluginUserInstance
```
--------------------------------
### Logseq Plugin API Components Reference for @logseq/libs
Source: https://logseq.github.io/plugins/types/PluginLocalIdentity
Comprehensive listing of interfaces, type aliases, classes, and functions available in the `@logseq/libs` library for Logseq plugin development. This section outlines the core building blocks for interacting with the Logseq application, including app information, block and page entities, editor proxies, and various utility types.
```APIDOC
@logseq/libs API Components:
Interfaces:
- AppGraphInfo
- AppInfo
- AppUserConfigs
- AppUserInfo
- BlockEntity
- IAppProxy
- IAssetsProxy
- IDBProxy
- IEditorProxy
- IGitProxy
- ILSPluginThemeManager
- ILSPluginUser
- IPluginSearchServiceHooks
- IUIProxy
- LSPluginBaseInfo
- LSPluginPkgConfig
- LegacyTheme
- PageEntity
- Theme
- IBatchBlock
- IDatom
- IEntityID
- IGitResult
- IHookEvent
- IUserConditionSlotHook
- IUserHook
- IUserOffHook
- IUserSlotHook
Type Aliases:
- PluginLocalIdentity: string
- BlockCommandCallback
- BlockCursorPosition
- BlockIdentity
- BlockPageName
- BlockUUID
- BlockUUIDTuple
- EntityID
- ExternalCommandType
- LSPluginUserEvents
- PageIdentity
- SearchBlockItem
- SearchFileItem
- SearchIndiceInitStatus
- SearchPageItem
- SettingSchemaDesc
- SimpleCommandCallback
- SimpleCommandKeybinding
- SlashCommandAction
- SlashCommandActionCmd
- StyleOptions
- StyleString
- ThemeMode
- UIBaseOptions
- UIContainerAttrs
- UIMsgKey
- UIMsgOptions
- UIOptions
- UIPathIdentity
- UIPathOptions
- UISlotIdentity
- UISlotOptions
- UserProxyTags
- WithOptional
Classes:
- LSPluginUser
Functions:
- setupPluginUserInstance
```
--------------------------------
### Get External Plugin (Logseq Plugin API)
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Retrieves an external plugin by its process ID (pid). Returns a Promise that resolves to an empty object, representing the plugin instance. This method was added in version 0.0.13.
```APIDOC
getExternalPlugin:
Signature: ((pid: string) => Promise<{}>)
Parameters:
pid: string
Returns: Promise<{}>
Added: 0.0.13
```
--------------------------------
### Logseq Plugin User Interface (ILSPluginUser) API Reference
Source: https://logseq.github.io/plugins/interfaces/ILSPluginUser
Documents the `ILSPluginUser` interface, providing access to various Logseq plugin functionalities including application control, data management, UI interactions, and event handling. This interface serves as the primary entry point for plugin developers to interact with the Logseq application.
```APIDOC
ILSPluginUser Interface:
Description: The main interface for Logseq plugin users to interact with the application.
Properties:
App: Access to application-level functionalities.
Assets: Manage plugin assets.
DB: Interact with the Logseq database.
Editor: Control editor-related operations.
Experiments: Access experimental features.
FileStorage: Handle file storage.
Git: Interact with Git.
Request: Make network requests.
UI: Control user interface elements.
baseInfo: Basic plugin information.
beforeunload: Event for before unload.
caller: Information about the caller.
connected: Connection status.
isMainUIVisible: Check if main UI is visible.
settings?: Plugin settings (optional).
Methods:
addListener(eventName: string, listener: Function): Adds an event listener for a specified event.
emit(eventName: string, ...args: any[]): Emits an event with optional arguments.
eventNames(): string[]: Returns an array of registered event names.
hideMainUI(): Hides the main plugin UI.
hideSettingsUI(): Hides the settings UI.
listenerCount(eventName: string): number: Returns the number of listeners for a specific event.
listeners(eventName: string): Function[]: Returns an array of listeners for a specific event.
off(eventName: string, listener: Function): Removes an event listener.
on(eventName: string, listener: Function): Adds an event listener (alias for addListener).
onSettingsChanged(): Event for settings changes.
once(eventName: string, listener: Function): Adds a one-time event listener that fires only once.
provideModel(model: object): Provides a model object to the plugin.
provideStyle(style: string): Provides a CSS style string to be injected.
provideTheme(theme: object): Provides a theme object to the plugin.
provideUI(ui: object): Provides UI elements to the plugin.
ready(): Event indicating the plugin is ready.
removeAllListeners(eventName?: string): Removes all listeners, or all for a specific event if eventName is provided.
removeListener(eventName: string, listener: Function): Removes a specific event listener.
resolveResourceFullUrl(resourcePath: string): string: Resolves a resource URL to its full path.
setMainUIAttrs(attrs: object): Sets attributes for the main UI element.
setMainUIInlineStyle(style: object): Sets inline CSS style for the main UI element.
showMainUI(): Shows the main plugin UI.
showSettingsUI(): Shows the settings UI.
toggleMainUI(): Toggles the visibility of the main UI.
updateSettings(newSettings: object): Updates plugin settings.
useSettingsSchema(schema: object): Uses a settings schema for plugin configuration.
```
--------------------------------
### Logseq Libs Package API Reference
Source: https://logseq.github.io/plugins/types/WithOptional
This section provides a structured overview of the public API surface for the `@logseq/libs` package, categorizing its exports into modules, classes, interfaces, type aliases, and functions. It serves as a quick reference for available types and functionalities essential for Logseq plugin development.
```APIDOC
Modules:
- @logseq/libs
Classes:
- LSPluginUser
Interfaces:
- AppGraphInfo
- AppInfo
- AppUserConfigs
- AppUserInfo
- BlockEntity
- IAppProxy
- IAssetsProxy
- IDBProxy
- IEditorProxy
- IGitProxy
- ILSPluginThemeManager
- ILSPluginUser
- IPluginSearchServiceHooks
- IUIProxy
- LSPluginBaseInfo
- LSPluginPkgConfig
- LegacyTheme
- PageEntity
- Theme
Type Aliases & Other Types:
- BlockCommandCallback
- BlockCursorPosition
- BlockIdentity
- BlockPageName
- BlockUUID
- BlockUUIDTuple
- EntityID
- ExternalCommandType
- IBatchBlock
- IDatom
- IEntityID
- IGitResult
- IHookEvent
- IUserConditionSlotHook
- IUserHook
- IUserOffHook
- IUserSlotHook
- LSPluginUserEvents
- PageIdentity
- PluginLocalIdentity
- SearchBlockItem
- SearchFileItem
- SearchIndiceInitStatus
- SearchPageItem
- SettingSchemaDesc
- SimpleCommandCallback
- SimpleCommandKeybinding
- SlashCommandAction
- SlashCommandActionCmd
- StyleOptions
- StyleString
- ThemeMode
- UIBaseOptions
- UIContainerAttrs
- UIMsgKey
- UIMsgOptions
- UIOptions
- UIPathIdentity
- UIPathOptions
- UISlotIdentity
- UISlotOptions
- UserProxyTags
- WithOptional
Functions:
- setupPluginUserInstance
```
--------------------------------
### API: Register Command Shortcut
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Registers a global keyboard shortcut for a Logseq plugin command. This function directly links a `SimpleCommandKeybinding` to a callback action, enabling quick access to plugin functionalities.
```APIDOC
registerCommandShortcut(
keybinding: SimpleCommandKeybinding,
action: SimpleCommandCallback
): void
Parameters:
keybinding: SimpleCommandKeybinding - The keybinding to register for the shortcut.
action: SimpleCommandCallback - The callback function to execute when the shortcut is activated.
Returns: void
```
--------------------------------
### Logseq IAppProxy Interface API Reference
Source: https://logseq.github.io/plugins/interfaces/IAppProxy
Comprehensive API documentation for the `IAppProxy` interface in Logseq, detailing its properties and methods for interacting with the Logseq application environment, managing plugins, and accessing graph data. This interface serves as the primary entry point for app-level operations within Logseq plugins.
```APIDOC
Interface IAppProxy
Description: App level APIs
Hierarchy: IAppProxy
Defined In: src/LSPlugin.ts:327
Properties:
_installPluginHook: (pid: string, hook: string) => void
Description: Internal hook to install a plugin hook.
Parameters:
pid: string - The plugin ID.
hook: string - The name of the hook.
Returns: void
Defined In: src/LSPlugin.ts:521
_uninstallPluginHook: (pid: string, hookOrAll: string | boolean) => void
Description: Internal hook to uninstall a plugin hook or all hooks for a plugin.
Parameters:
pid: string - The plugin ID.
hookOrAll: string | boolean - The name of the hook to uninstall, or true to uninstall all hooks.
Returns: void
Defined In: src/LSPlugin.ts:522
clearRightSidebarBlocks: (opts?: { close: boolean; }) => void
Description: Clears blocks from the right sidebar.
Parameters:
opts?: object - Optional configuration.
close: boolean - If true, closes the right sidebar after clearing blocks.
Returns: void
Defined In: src/LSPlugin.ts:467
execGitCommand: (args: string[]) => Promise
Description: Executes a Git command.
Deprecated: Use `logseq.Git.execCommand` instead.
Link: https://github.com/desktop/dugite/blob/master/docs/api/exec.md
Parameters:
args: string[] - An array of arguments for the Git command.
Returns: Promise - A promise that resolves with the command output.
Defined In: src/LSPlugin.ts:424
getCurrentGraph: () => Promise
Description: Retrieves information about the current graph.
Returns: Promise - A promise that resolves with the current graph's information.
Defined In: src/LSPlugin.ts:427
getCurrentGraphConfigs: () => Promise
Description: Retrieves the configurations for the current graph.
Returns: Promise - A promise that resolves with the current graph's configurations.
Defined In: src/LSPlugin.ts:428
// ... (Other properties listed in Index, but not detailed in the provided text)
Methods:
registerSearchService
// ... (Other methods listed in Index, but not detailed in the provided text)
```
--------------------------------
### API: selectBlock Method
Source: https://logseq.github.io/plugins/interfaces/IEditorProxy
API documentation for the `selectBlock` method, which asynchronously selects a specified block within Logseq.
```APIDOC
selectBlock:
Signature: (srcBlock: [BlockIdentity](../types/BlockIdentity.html)): Promise
Parameters:
srcBlock: [BlockIdentity](../types/BlockIdentity.html)
Returns: Promise
```