Enhance/plugins apis (#10127)

* enhance(api): add page to recent for route api

* enhance(api): support open block in right sidebar with entity id
This commit is contained in:
Charlie
2023-09-06 22:49:18 +08:00
committed by GitHub
parent 12642f5777
commit 331afbc04f
4 changed files with 27 additions and 15 deletions

View File

@@ -811,7 +811,7 @@ export interface IEditorProxy extends Record<string, any> {
opts?: { replaceState: boolean }
) => void
openInRightSidebar: (uuid: BlockUUID) => void
openInRightSidebar: (id: BlockUUID | EntityID) => void
/**
* @example https://github.com/logseq/logseq-plugin-samples/tree/master/logseq-a-translator

View File

@@ -197,7 +197,7 @@
(defn open-block-in-sidebar!
[block-id]
(when block-id
(when-let [block (db/entity [:block/uuid block-id])]
(when-let [block (db/entity (if (number? block-id) block-id [:block/uuid block-id]))]
(let [page? (nil? (:block/page block))]
(state/sidebar-add-block!
(state/get-current-repo)

View File

@@ -77,11 +77,13 @@
(recent-handler/add-page-to-recent! (state/get-current-repo) page-name
click-from-recent?)
(let [m (cond->
(default-page-route page-name)
(default-page-route page-name)
anchor
(assoc :query-params {:anchor anchor})
push
(assoc :push push))]
(boolean? push)
(assoc :push push))]
(redirect! m)))))
(defn redirect-to-whiteboard!

View File

@@ -13,6 +13,7 @@
[frontend.components.plugins :as plugins]
[frontend.config :as config]
[frontend.handler.config :as config-handler]
[frontend.handler.route :as route-handler]
[frontend.db :as db]
[frontend.db.model :as db-model]
[frontend.db.query-dsl :as query-dsl]
@@ -449,17 +450,23 @@
(def ^:export push_state
(fn [^js k ^js params ^js query]
(rfe/push-state
(keyword k)
(bean/->clj params)
(bean/->clj query))))
(let [k (keyword k)
page? (= k :page)
params (bean/->clj params)
query (bean/->clj query)]
(if-let [page-name (and page? (:name params))]
(route-handler/redirect-to-page! page-name {:anchor (:anchor query) :push true})
(rfe/push-state k params query)))))
(def ^:export replace_state
(fn [^js k ^js params ^js query]
(rfe/replace-state
(keyword k)
(bean/->clj params)
(bean/->clj query))))
(let [k (keyword k)
page? (= k :page)
params (bean/->clj params)
query (bean/->clj query)]
(if-let [page-name (and page? (:name params))]
(route-handler/redirect-to-page! page-name {:anchor (:anchor query) :push false})
(rfe/replace-state k params query)))))
(defn ^:export get_external_plugin
[pid]
@@ -563,8 +570,11 @@
page-handler/rename!)
(defn ^:export open_in_right_sidebar
[block-uuid]
(editor-handler/open-block-in-sidebar! (sdk-utils/uuid-or-throw-error block-uuid)))
[block-id-or-uuid]
(editor-handler/open-block-in-sidebar!
(if (number? block-id-or-uuid)
block-id-or-uuid
(sdk-utils/uuid-or-throw-error block-id-or-uuid))))
(defn ^:export new_block_uuid []
(str (db/new-block-id)))