ClojureScript Wrapper for @logseq/libs - Build Better Logseq Plugins
Newsletter about software engineering, team management, team building, books and lots of notes I take after reading/studying (mine or yours)… :D
@logseq/libs for ClojureScript provides a native bridge for developing Logseq plugins using ClojureScript. This wrapper transforms the TypeScript-based plugin API into an idiomatic ClojureScript interface, allowing developers to leverage functional programming and REPL-driven development while maintaining full compatibility with the Logseq ecosystem.
Key Features
- Write plugins in the same language as Logseq's core
- Leverage ClojureScript's elegant syntax and functional programming paradigms
- Benefit from ClojureScript's type system while maintaining JavaScript interop
- Seamless integration with existing Logseq plugin ecosystem
- Access to both ClojureScript and JavaScript libraries
Getting Started
To get started, add the following dependency to your deps.edn
:
{:deps {run.avelino/logseq-libs {:mvn/version "0.2.1.0"}}}
Here's a simple example of a plugin:
(ns my-awesome-plugin.core
(:require [run.avelino.logseq-libs.core :as ls]
[run.avelino.logseq-libs.ui :as ui]))
(ls/ready!
(fn []
(ui/show-msg! "Plugin loaded!")
(ls/register-command-palette!
{:key "hello-world"
:label "Greet User"
:keybinding "mod+shift+h"
:callback #(ui/show-msg! "Hello from ClojureScript!")})))
API Reference
Core Module (run.avelino.logseq-libs.core
)
Core functionality for plugin lifecycle and settings management.
(require '[run.avelino.logseq-libs.core :as ls])
Plugin Lifecycle
ready! [callback]
- Initialize plugin with callback functiondisable-plugin! []
- Disable the current pluginreload-plugin! []
- Reload the current plugin
Settings Management
register-settings! [settings]
- Register plugin settings schemaget-settings! []
- Get current plugin settingsupdate-settings! [settings]
- Update plugin settings
Command Registration
register-command! [cmd]
- Register a single commandregister-command-palette! [cmd]
- Register a command in the command paletteregister-block-command! [cmd]
- Register a block-level command
UI Module (run.avelino.logseq-libs.ui
)
User interface components and notifications.
(require '[run.avelino.logseq-libs.ui :as ui])
Notifications
show-msg! [content & opts]
- Show notification messageshow-error! [content]
- Show error notificationshow-warning! [content]
- Show warning notification
UI Components
open-modal! [opts]
- Open a modal dialogclose-modal! []
- Close current modalshow-prompt! [content & opts]
- Show prompt dialogshow-picker! [opts]
- Show item picker dialog
Editor Module (run.avelino.logseq-libs.editor
)
Block and page manipulation functions.
(require '[run.avelino.logseq-libs.editor :as editor])
Page Operations
get-current-page! []
- Get current page dataget-page! [name]
- Get page by namecreate-page! [name content & opts]
- Create new pagedelete-page! [name]
- Delete page by name
Block Operations
get-block! [uuid]
- Get block by UUIDinsert-block! [uuid content & opts]
- Insert new blockupdate-block! [uuid content]
- Update block contentremove-block! [uuid]
- Remove block by UUIDget-block-property! [uuid key]
- Get block propertyset-block-property! [uuid key value]
- Set block property
DB Module (run.avelino.logseq-libs.db
)
Graph database queries and operations.
(require '[run.avelino.logseq-libs.db :as db])
Queries
q! [query & inputs]
- Execute Datalog querydatascript-query! [query & inputs]
- Execute raw Datascript queryget-current-graph! []
- Get current graph infoget-pages! [& opts]
- Get all pagesget-page-blocks! [page-name]
- Get all blocks for a page
Git Module (run.avelino.logseq-libs.git
)
Version control operations.
(require '[run.avelino.logseq-libs.git :as git])
Repository Operations
get-head-commit! []
- Get current HEAD commitcheckout! [ref]
- Checkout specific referencecreate-branch! [name]
- Create new branchget-branches! []
- List all branches
Assets Module (run.avelino.logseq-libs.assets
)
File and asset management.
(require '[run.avelino.logseq-libs.assets :as assets])
Asset Operations
make-asset-url! [path]
- Create asset URLupload-asset! [file]
- Upload asset filelist-assets! []
- List all assetsremove-asset! [path]
- Remove asset
Theme Module (run.avelino.logseq-libs.theme
)
Theme customization and management.
(require '[run.avelino.logseq-libs.theme :as theme])
Theme Operations
get-theme! []
- Get current themeset-theme! [theme]
- Set active themetoggle-theme! []
- Toggle between light/dark themesadd-style! [style]
- Add custom CSS stylesremove-style! [id]
- Remove custom styles
Utils Module (run.avelino.logseq-libs.utils
)
Utility functions for common plugin operations.
(require '[run.avelino.logseq-libs.utils :as utils])
Utility Functions
format-date! [date format]
- Format date with specified formatuuid! []
- Generate a new UUIDdebounce! [f ms]
- Create a debounced version of a functionthrottle! [f ms]
- Create a throttled version of a functionparse-json! [str]
- Parse JSON string to ClojureScript data structureto-json! [data]
- Convert ClojureScript data to JSON string
Macros Module (run.avelino.logseq-libs.macros
)
Useful macros for plugin development.
(require '[run.avelino.logseq-libs.macros :as macros :include-macros true])
Available Macros
defplugin
- Define a new plugin with lifecycle hookswith-promise->
- Thread-first macro for promise-based operationswith-promise->>
- Thread-last macro for promise-based operationscatch->error
- Catch and handle errors in promise chains
Why ClojureScript for Logseq Plugins?
- Native Development: Use the same language as Logseq's core for deeper understanding and better integration
- Functional Programming: Leverage immutable data structures and functional paradigms for more reliable plugins
- REPL-Driven Development: Test and modify your plugin in real-time
- Concise, Readable Code: Write more expressive code with ClojureScript's elegant syntax
The project provides ClojureScript wrappers for all major Logseq plugin APIs including core functionality, UI components, editor operations, database queries, git operations, and theme customization.
Join us in building the future of knowledge management tools with ClojureScript! Visit our GitHub repository to get started or contribute to the project.