mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +00:00
enhance(api): improve append_block_in_page to handle current page context
This commit is contained in:
@@ -61,6 +61,8 @@
|
||||
(page/new-page "test-block-apis")
|
||||
(ls-api-call! :ui.showMsg "hello world" "info")
|
||||
(let [ret (ls-api-call! :editor.appendBlockInPage "test-block-apis" "append-block-in-page-0")
|
||||
ret1 (ls-api-call! :editor.appendBlockInPage "append-block-in-current-page-0")
|
||||
_ (assert-api-ls-block! ret1)
|
||||
uuid' (assert-api-ls-block! ret)]
|
||||
(-> (ls-api-call! :editor.insertBlock uuid' "insert-0")
|
||||
(assert-api-ls-block!))
|
||||
|
||||
@@ -1078,15 +1078,21 @@
|
||||
|
||||
(defn ^:export append_block_in_page
|
||||
[uuid-or-page-name content ^js opts]
|
||||
(p/let [_ (<ensure-page-loaded uuid-or-page-name)
|
||||
page? (not (util/uuid-string? uuid-or-page-name))
|
||||
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
|
||||
_ (and page-not-exist? (page-handler/<create! uuid-or-page-name
|
||||
{:redirect? false
|
||||
:format (state/get-preferred-format)}))]
|
||||
(when-let [block (db-model/get-page uuid-or-page-name)]
|
||||
(let [target (str (:block/uuid block))]
|
||||
(insert_block target content opts)))))
|
||||
(let [current-page? (or (and (nil? content) (nil? opts))
|
||||
(and (nil? opts) (some->> content (instance? js/Object))))
|
||||
opts (if current-page? content opts)
|
||||
content (if current-page? uuid-or-page-name content)
|
||||
uuid-or-page-name (if current-page? (state/get-current-page)
|
||||
uuid-or-page-name)]
|
||||
(p/let [_ (<ensure-page-loaded uuid-or-page-name)
|
||||
page? (not (util/uuid-string? uuid-or-page-name))
|
||||
page-not-exist? (and page? (nil? (db-model/get-page uuid-or-page-name)))
|
||||
_ (and page-not-exist? (page-handler/<create! uuid-or-page-name
|
||||
{:redirect? false
|
||||
:format (state/get-preferred-format)}))]
|
||||
(when-let [block (db-model/get-page uuid-or-page-name)]
|
||||
(let [target (str (:block/uuid block))]
|
||||
(insert_block target content opts))))))
|
||||
|
||||
;; plugins
|
||||
(defn ^:export validate_external_plugins [urls]
|
||||
|
||||
Reference in New Issue
Block a user