Files
logseq/src/main/frontend/search/plugin.cljs
Charlie dda1f9bd9f Enhance / Plugin APIs (#6945)
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
2022-11-22 22:00:29 +08:00

41 lines
1.6 KiB
Clojure

(ns frontend.search.plugin
"Plugin service implementation of search protocol"
(:require [frontend.state :as state]
[frontend.handler.plugin :as plugin-handler]
[frontend.search.protocol :as protocol]
[cljs-bean.core :as bean]))
(defn call-service!
([service event payload] (call-service! service event payload false))
([service event payload reply?]
(when-let [^js pl (plugin-handler/get-plugin-inst (:pid service))]
(let [{:keys [pid name]} service
hookEvent (str "service:" event ":" name)]
(.call (.-caller pl) hookEvent (bean/->js (merge {:graph (state/get-current-repo)} payload)))
(when reply?
(.once (.-caller pl) (str hookEvent ":reply")
(fn [^js e]
(state/update-plugin-search-engine pid name #(assoc % :result (bean/->clj e))))))))))
(deftype Plugin [service repo]
protocol/Engine
(query [_this q opts]
(call-service! service "search:query" (merge {:q q} opts) true))
(rebuild-blocks-indice! [_this]
;; Not pushing all data for performance temporarily
;;(let [blocks (search-db/build-blocks-indice repo)])
(call-service! service "search:rebuildBlocksIndice" {}))
(transact-blocks! [_this data]
(let [{:keys [blocks-to-remove-set blocks-to-add]} data]
(call-service! service "search:transactBlocks"
{:data {:added blocks-to-add
:removed blocks-to-remove-set}})))
(truncate-blocks! [_this]
(call-service! service "search:truncateBlocks" {}))
(remove-db! [_this]
(call-service! service "search:removeDb" {})))