Browse Source

refactor: move editor impl to db-based and file-based

Tienson Qin 2 years ago
parent
commit
7e44ff09a8

+ 2 - 2
src/main/frontend/handler/code.cljs

@@ -9,7 +9,7 @@
             [goog.object :as gobj]
             [logseq.graph-parser.utf8 :as utf8]
             [logseq.common.path :as path]
-            [frontend.handler.editor.impl.db :as db-impl]))
+            [frontend.handler.db-based.editor :as db-editor-handler]))
 
 (defn save-code-editor!
   []
@@ -44,7 +44,7 @@
 
             (and (not-empty (:file-path config))
                  (config/db-based-graph? repo))
-            (db-impl/save-file! (:file-path config) value)
+            (db-editor-handler/save-file! (:file-path config) value)
 
             (not-empty (:file-path config))
             (let [path (:file-path config)

+ 1 - 1
src/main/frontend/handler/editor/impl/db.cljs → src/main/frontend/handler/db_based/editor.cljs

@@ -1,4 +1,4 @@
-(ns frontend.handler.editor.impl.db
+(ns frontend.handler.db-based.editor
   "DB-based graph implementation"
   (:require [clojure.string :as string]
             [frontend.config :as config]

+ 4 - 1
src/main/frontend/handler/db_based/recent.cljs

@@ -18,4 +18,7 @@
 (defn get-recent-pages
   []
   (->> (db/get-key-value :recent/pages)
-       (map #(:block/original-name (db/entity [:block/uuid %])))))
+       (map (fn [id]
+              (let [e (db/entity [:block/uuid id])]
+                (or (:block/original-name e)
+                    (:block/uuid e)))))))

+ 13 - 6
src/main/frontend/handler/editor.cljs

@@ -25,6 +25,8 @@
             [frontend.handler.notification :as notification]
             [frontend.handler.repeated :as repeated]
             [frontend.handler.route :as route-handler]
+            [frontend.handler.db-based.editor :as db-editor-handler]
+            [frontend.handler.file-based.editor :as file-editor-handler]
             [frontend.mobile.util :as mobile-util]
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.transaction :as outliner-tx]
@@ -43,7 +45,6 @@
             [frontend.util.property :as property]
             [frontend.util.text :as text-util]
             [frontend.util.thingatpt :as thingatpt]
-            [frontend.handler.editor.impl :as editor-impl]
             [goog.dom :as gdom]
             [goog.dom.classes :as gdom-classes]
             [goog.object :as gobj]
@@ -234,6 +235,12 @@
     (doseq [block blocks]
       (gdom-classes/remove block "block-highlight"))))
 
+(defn wrap-parse-block
+  [block]
+  (if (config/db-based-graph? (state/get-current-repo))
+    (db-editor-handler/wrap-parse-block block)
+    (file-editor-handler/wrap-parse-block block)))
+
 (defn- save-block-inner!
   [block value opts]
   (let [block {:db/id (:db/id block)
@@ -243,7 +250,7 @@
      "Save block: "
      (let [original-uuid (:block/uuid (db/entity (:db/id block)))
            uuid-changed? (not= (:block/uuid block) original-uuid)
-           block' (-> (editor-impl/wrap-parse-block block)
+           block' (-> (wrap-parse-block block)
                       ;; :block/uuid might be changed when backspace/delete
                       ;; a block that has been refed
                       (assoc :block/uuid (:block/uuid block)))
@@ -352,7 +359,7 @@
                :block/content ""}
         prev-block (-> (merge (select-keys block [:block/parent :block/left :block/format
                                                   :block/page :block/journal?]) new-m)
-                       (editor-impl/wrap-parse-block))
+                       (wrap-parse-block))
         left-block (db/pull (:db/id (:block/left block)))]
     (when input-text-selected?
       (let [selection-start (util/get-selection-start input)
@@ -384,7 +391,7 @@
                :block/content snd-block-text}
         next-block (-> (merge (select-keys block [:block/parent :block/left :block/format
                                                   :block/page :block/journal?]) new-m)
-                       (editor-impl/wrap-parse-block))
+                       (wrap-parse-block))
         sibling? (when block-self? false)]
     (outliner-insert-block! config current-block next-block {:sibling? sibling?
                                                              :keep-uuid? true})
@@ -486,7 +493,7 @@
                                  (:db/id block)
                                  (:db/id (:block/page new-block))))
               new-block (-> new-block
-                            (editor-impl/wrap-parse-block)
+                            (wrap-parse-block)
                             (assoc :block/uuid (or custom-uuid (db/new-block-id))))
               [block-m sibling?] (cond
                                    before?
@@ -1959,7 +1966,7 @@
                                   (property-edit/insert-properties-when-file-based repo format content props))
                     ast (mldoc/->edn content* (gp-mldoc/default-config format))
                     blocks (->> (block/extract-blocks ast content* format {:page-name page-name})
-                                (map editor-impl/wrap-parse-block))
+                                (map wrap-parse-block))
                     fst-block (first blocks)
                     fst-block (if (and keep-uuid? (uuid? (:uuid block)))
                                 (assoc fst-block :block/uuid (:uuid block))

+ 0 - 11
src/main/frontend/handler/editor/impl.cljs

@@ -1,11 +0,0 @@
-(ns frontend.handler.editor.impl
-  (:require [frontend.config :as config]
-            [frontend.handler.editor.impl.file :as file]
-            [frontend.handler.editor.impl.db :as db]
-            [frontend.state :as state]))
-
-(defn wrap-parse-block
-  [block]
-  (if (config/db-based-graph? (state/get-current-repo))
-    (db/wrap-parse-block block)
-    (file/wrap-parse-block block)))

+ 1 - 1
src/main/frontend/handler/editor/impl/file.cljs → src/main/frontend/handler/file_based/editor.cljs

@@ -1,4 +1,4 @@
-(ns frontend.handler.editor.impl.file
+(ns frontend.handler.file-based.editor
   "File-based graph implementation"
   (:require [clojure.string :as string]
             [frontend.config :as config]

+ 2 - 2
src/main/frontend/handler/import.cljs

@@ -20,7 +20,7 @@
             [frontend.handler.editor :as editor]
             [frontend.handler.notification :as notification]
             [frontend.util :as util]
-            [frontend.handler.editor.impl :as editor-impl]
+            [frontend.handler.editor :as editor-handler]
             [clojure.core.async :as async]
             [medley.core :as medley]))
 
@@ -93,7 +93,7 @@
           page-name (:title headers)
           parsed-blocks (->>
                          (block/extract-blocks parsed-blocks "" :markdown {:page-name page-name})
-                         (mapv editor-impl/wrap-parse-block))]
+                         (mapv editor-handler/wrap-parse-block))]
       (when (not (db/page-exists? page-name))
         (page-handler/create! page-name {:redirect? false}))
       (let [page-block (db/entity [:block/name (util/page-name-sanity-lc page-name)])