浏览代码

fix: lint and append_block_in_page

Tienson Qin 1 周之前
父节点
当前提交
6e5399bf47

+ 2 - 0
deps/db/.carve/ignore

@@ -46,5 +46,7 @@ logseq.db.sqlite.gc/gc-kvs-table!
 logseq.db.sqlite.gc/gc-kvs-table-node-version!
 ;; API
 logseq.db.sqlite.gc/ensure-no-garbage
+;; API
+logseq.db.common.entity-util/entity->map
 ;; documenting keywords
 logseq.db.frontend.kv-entity/kv-entities

+ 4 - 4
deps/outliner/src/logseq/outliner/property.cljs

@@ -318,11 +318,11 @@
       v
 
       (= property-type :page)
-      (let [ex-data {:property-id property-id
-                     :property-type property-type
-                     :v v}]
+      (let [error-data {:property-id property-id
+                        :property-type property-type
+                        :v v}]
         (if (or (string/blank? v) (not (string? v)))
-          (throw (ex-info "Value should be non-empty string" ex-data))
+          (throw (ex-info "Value should be non-empty string" error-data))
           (let [page (ldb/get-page @conn v)]
             (if (entity-util/page? page)
               (:db/id page)

+ 11 - 8
src/main/logseq/api/block.cljs

@@ -31,29 +31,32 @@
 
 (defn get-sanitized-plugin-id
   [^js plugin]
-  (when (some-> js/window.LSPlugin (.-PluginLocal))
-    (some->> plugin (.-id) sanitize-user-property-name)))
+  (or
+   (when (some-> js/window.LSPlugin (.-PluginLocal))
+     (some->> plugin (.-id) sanitize-user-property-name))
+   "_test_plugin"))
 
 (defn resolve-property-prefix-for-db
   [^js plugin]
   (let [plugin-id (get-sanitized-plugin-id plugin)]
     (when-not plugin-id
-      (js/console.error "Can't get current plugin-id")
-      (throw (ex-info "Can't get current plugin-id"
+      (js/console.error "Can't get current plugin id")
+      (throw (ex-info "Can't get current plugin id"
                       {:plugin plugin})))
     (str plugin-property-prefix plugin-id)))
 
 (defn get-db-ident-from-property-name
   "Finds a property :db/ident for a given property name"
   [property-name plugin]
-  (when-not (string? property-name)
-    (throw (ex-info "property-name should be a string" {:property-name property-name})))
-  (let [property-key (keyword property-name)]
+  (let [property-name' (if-not (string? property-name)
+                         (str property-name)
+                         property-name)
+        property-key (keyword property-name')]
     (if (qualified-keyword? property-key)
       property-key
       ;; plugin property
       (let [plugin-ns (resolve-property-prefix-for-db plugin)]
-        (keyword plugin-ns (db-ident/normalize-ident-name-part property-name))))))
+        (keyword plugin-ns (db-ident/normalize-ident-name-part property-name'))))))
 
 (defn plugin-property-key?
   [ident]

+ 34 - 22
src/main/logseq/api/editor.cljs

@@ -414,29 +414,41 @@
           opts' (assoc opts :before false :sibling false :start true)]
       (insert_block (str (:block/uuid block)) content (bean/->js opts')))))
 
+(defn- get-current-page-or-today
+  []
+  (or
+   (state/get-current-page)
+   (date/today)))
+
 (defn append_block_in_page
-  [uuid-or-page-name content ^js opts]
-  (let [uuid-or-page-name (or
-                           uuid-or-page-name
-                           (state/get-current-page)
-                           (date/today))]
-    (p/let [_ (<ensure-page-loaded uuid-or-page-name)
-            page? (not (util/uuid-string? uuid-or-page-name))
-            page (db-model/get-page uuid-or-page-name)
-            page-not-exist? (and page? (nil? page))
-            new-page (when page-not-exist?
-                       (page-handler/<create! uuid-or-page-name
-                                              {:redirect? false
-                                               :format (state/get-preferred-format)}))
-            block (or page new-page)]
-      (let [children (:block/_parent block)
-            [target sibling?] (if (seq children)
-                                [(last (ldb/sort-by-order children)) true]
-                                [block false])
-            target-id (str (:block/uuid target))
-            opts (-> (bean/->clj opts)
-                     (assoc :sibling sibling?))]
-        (insert_block target-id content opts)))))
+  ([content]
+   (append_block_in_page (get-current-page-or-today) content nil))
+  ([uuid-or-page-name-or-content content-or-opts]
+   (if (string? content-or-opts)
+     (append_block_in_page uuid-or-page-name-or-content content-or-opts nil)
+     (append_block_in_page (get-current-page-or-today) uuid-or-page-name-or-content content-or-opts)))
+  ([uuid-or-page-name content ^js opts]
+   (let [uuid-or-page-name (or
+                            uuid-or-page-name
+                            (state/get-current-page)
+                            (date/today))]
+     (p/let [_ (<ensure-page-loaded uuid-or-page-name)
+             page? (not (util/uuid-string? uuid-or-page-name))
+             page (db-model/get-page uuid-or-page-name)
+             page-not-exist? (and page? (nil? page))
+             new-page (when page-not-exist?
+                        (page-handler/<create! uuid-or-page-name
+                                               {:redirect? false
+                                                :format (state/get-preferred-format)}))
+             block (or page new-page)]
+       (let [children (:block/_parent block)
+             [target sibling?] (if (seq children)
+                                 [(last (ldb/sort-by-order children)) true]
+                                 [block false])
+             target-id (str (:block/uuid target))
+             opts (-> (bean/->clj opts)
+                      (assoc :sibling sibling?))]
+         (insert_block target-id content opts))))))
 
 (defn download_graph_db
   []