enhance(api): improve append_block_in_page to handle current page context

This commit is contained in:
charlie
2025-08-26 13:38:59 +08:00
committed by Gabriel Horner
parent 4b5a16628a
commit bc46cf7d14
2 changed files with 17 additions and 9 deletions

View File

@@ -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!))

View File

@@ -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]