Tienson Qin 4 лет назад
Родитель
Сommit
12ea1a29f3

+ 3 - 3
libs/src/LSPlugin.ts

@@ -273,7 +273,7 @@ export interface IEditorProxy extends Record<string, any> {
   insertBlock: (
     srcBlock: BlockIdentity,
     content: string,
-    opts?: Partial<{ before: boolean; sibling: boolean; props: {} }>
+    opts?: Partial<{ before: boolean; sibling: boolean; properties: {} }>
   ) => Promise<BlockEntity | null>
 
   insertBatchBlock: (
@@ -285,7 +285,7 @@ export interface IEditorProxy extends Record<string, any> {
   updateBlock: (
     srcBlock: BlockIdentity,
     content: string,
-    opts?: Partial<{ props: {} }>
+    opts?: Partial<{ properties: {} }>
   ) => Promise<void>
 
   removeBlock: (
@@ -483,4 +483,4 @@ export interface ILSPluginUser extends EventEmitter<LSPluginUserEvents> {
   App: IAppProxy & Record<string, any>
   Editor: IEditorProxy & Record<string, any>
   DB: IDBProxy
-}
+}

+ 20 - 9
src/main/frontend/handler/editor.cljs

@@ -628,9 +628,12 @@
    (state/set-editor-op! nil)))
 
 (defn api-insert-new-block!
-  [content {:keys [page block-uuid sibling? attributes]}]
+  [content {:keys [page block-uuid sibling? before? properties]
+            :or {sibling? false
+                 before? false}}]
   (when (or page block-uuid)
-    (let [sibling? (if page false sibling?)
+    (let [before? (if page false before?)
+          sibling? (if before? true (if page false sibling?))
           block (if page
                   (db/entity [:block/name (string/lower-case page)])
                   (db/entity [:block/uuid block-uuid]))]
@@ -641,7 +644,7 @@
                                  blocks (db/sort-by-left children block)
                                  last-block-id (:db/id (last blocks))]
                              (when last-block-id
-                                 (db/pull last-block-id))))
+                               (db/pull last-block-id))))
               new-block (-> (select-keys block [:block/page :block/file :block/journal?
                                                 :block/journal-day])
                             (assoc :block/content content
@@ -652,27 +655,35 @@
                             (wrap-parse-block)
                             (assoc :block/uuid (db/new-block-id)))
               new-block (if (:block/page new-block)
-                          new-block
+                          (assoc new-block :block/page (:db/id (:block/page new-block)))
                           (assoc new-block :block/page (:db/id block)))
               new-block (if-let [db-id (:db/id (:block/file block))]
                           (assoc new-block :block/file db-id)
+                          new-block)
+              new-block (if (and (map? properties) (seq properties))
+                          (update new-block :block/properties (fn [m] (merge m properties)))
                           new-block)]
           (let [[block-m sibling?] (cond
+                                     before?
+                                     (let [block (db/pull (:db/id (:block/left block)))
+                                           sibling? (if (:block/name block) false sibling?)]
+                                       [block sibling?])
+
                                      sibling?
                                      [(db/pull (:db/id block)) sibling?]
 
                                      last-block
                                      [last-block true]
 
-                                     page
-                                     [(db/pull (:db/id block)) false]
+                                     block
+                                     [(db/pull (:db/id block)) sibling?]
 
                                      ;; FIXME: assert
                                      :else
                                      nil)]
-            (outliner-insert-block! {:skip-save-current-block? true} block-m new-block sibling?)
-            (db/refresh! repo {:key :block/insert
-                               :data [(assoc block-m :block/page block)]})))))))
+            (when block-m
+              (outliner-insert-block! {:skip-save-current-block? true} block-m new-block sibling?)
+              (ui-handler/re-render-root!))))))))
 
 (defn insert-first-page-block-if-not-exists!
   [page-name]

+ 1 - 1
src/main/frontend/handler/page.cljs

@@ -322,7 +322,7 @@
     (editor-handler/api-insert-new-block!
      content
      {:page "Contents"})
-    (notification/show! "Added to contents!" :success)
+    (notification/show! (util/format "Added to %s!" (state/get-favorites-name)) :success)
     (editor-handler/clear-when-saved!)))
 
 (defn has-more-journals?

+ 1 - 1
src/main/frontend/state.cljs

@@ -1327,4 +1327,4 @@
 
 (defn get-favorites-name
   []
-  (:name/favorites (get-config)))
+  (or (:name/favorites (get-config)) "Favorites"))

+ 6 - 4
src/main/logseq/api.cljs

@@ -235,12 +235,15 @@
 
 (def ^:export insert_block
   (fn [block-uuid-or-page-name content ^js opts]
-    (let [{:keys [before sibling isPageBlock props]} (bean/->clj opts)
+    (let [{:keys [before sibling isPageBlock properties]} (bean/->clj opts)
           page-name (and isPageBlock block-uuid-or-page-name)
           block-uuid (if isPageBlock nil (medley/uuid block-uuid-or-page-name))
           new-block (editor-handler/api-insert-new-block!
-                     content {:block-uuid block-uuid :sibling? sibling :page page-name})]
-
+                     content
+                     {:block-uuid block-uuid
+                      :sibling? sibling
+                      :page page-name
+                      :properties properties})]
       (bean/->js (normalize-keyword-for-json new-block)))))
 
 (def ^:export insert_batch_block
@@ -266,7 +269,6 @@
           repo (state/get-current-repo)
           edit-input (state/get-edit-input-id)
           editing? (and edit-input (string/ends-with? edit-input block-uuid))]
-
       (if editing?
         (state/set-edit-content! edit-input content)
         (editor-handler/save-block! repo (medley/uuid block-uuid) content))