mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 17:06:23 +00:00
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
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
:search/mode :global
|
||||
:search/result nil
|
||||
:search/graph-filters []
|
||||
:search/engines {}
|
||||
|
||||
;; modals
|
||||
:modal/dropdowns {}
|
||||
@@ -188,6 +189,7 @@
|
||||
:plugin/installed-ui-items {}
|
||||
:plugin/installed-resources {}
|
||||
:plugin/installed-hooks {}
|
||||
:plugin/installed-services {}
|
||||
:plugin/simple-commands {}
|
||||
:plugin/selected-theme nil
|
||||
:plugin/selected-unpacked-pkg nil
|
||||
@@ -1454,6 +1456,61 @@ Similar to re-frame subscriptions"
|
||||
[:plugin/installed-resources (keyword pid) (keyword type) key] resource)
|
||||
resource)))
|
||||
|
||||
(defn get-plugin-services
|
||||
[pid type]
|
||||
(when-let [installed (and pid (:plugin/installed-services @state))]
|
||||
(some->> (seq (get installed (keyword pid)))
|
||||
(filterv #(= type (:type %))))))
|
||||
|
||||
(defn install-plugin-service
|
||||
([pid type name] (install-plugin-service pid type name nil))
|
||||
([pid type name opts]
|
||||
(when-let [pid (and pid type name (keyword pid))]
|
||||
(let [exists (get-plugin-services pid type)]
|
||||
(when-let [service (and (or (not exists) (not (some #(= name (:name %)) exists)))
|
||||
{:pid pid :type type :name name :opts opts})]
|
||||
(update-state! [:plugin/installed-services pid] #(conj (vec %) service))
|
||||
|
||||
;; search engines state for results
|
||||
(when (= type :search)
|
||||
(set-state! [:search/engines (str pid name)] service)))))))
|
||||
|
||||
(defn uninstall-plugin-service
|
||||
[pid type-or-all]
|
||||
(when-let [pid (keyword pid)]
|
||||
(when-let [installed (get (:plugin/installed-services @state) pid)]
|
||||
(let [remove-all? (or (true? type-or-all) (nil? type-or-all))
|
||||
remains (if remove-all? nil (filterv #(not= type-or-all (:type %)) installed))
|
||||
removed (if remove-all? installed (filterv #(= type-or-all (:type %)) installed))]
|
||||
(set-state! [:plugin/installed-services pid] remains)
|
||||
|
||||
;; search engines state for results
|
||||
(when-let [removed' (seq (filter #(= :search (:type %)) removed))]
|
||||
(update-state! :search/engines #(apply dissoc % (mapv (fn [{:keys [pid name]}] (str pid name)) removed'))))))))
|
||||
|
||||
(defn get-all-plugin-services-with-type
|
||||
[type]
|
||||
(when-let [installed (vals (:plugin/installed-services @state))]
|
||||
(mapcat (fn [s] (filter #(= (keyword type) (:type %)) s)) installed)))
|
||||
|
||||
(defn get-all-plugin-search-engines
|
||||
[]
|
||||
(:search/engines @state))
|
||||
|
||||
(defn update-plugin-search-engine
|
||||
[pid name f]
|
||||
(when-let [pid (keyword pid)]
|
||||
(set-state! :search/engines
|
||||
(update-vals (get-all-plugin-search-engines)
|
||||
#(if (and (= pid (:pid %)) (= name (:name %)))
|
||||
(f %) %)))))
|
||||
|
||||
(defn reset-plugin-search-engines
|
||||
[]
|
||||
(when-let [engines (get-all-plugin-search-engines)]
|
||||
(set-state! :search/engines
|
||||
(update-vals engines #(assoc % :result nil)))))
|
||||
|
||||
(defn install-plugin-hook
|
||||
[pid hook]
|
||||
(when-let [pid (keyword pid)]
|
||||
|
||||
Reference in New Issue
Block a user