Browse Source

enhance: Add EDN export to page+block menus

for db graphs for more user-friendly use of the feature and to provide
consistency. Addresses a request in #alpha-db-feedback
Gabriel Horner 7 months ago
parent
commit
445be61fcf

+ 2 - 1
deps/db/src/logseq/db/sqlite/export.cljs

@@ -769,7 +769,8 @@
           (build-block-export db (:block-id options))
           :page
           (build-page-export db (:page-id options))
-          :view-nodes
+          ;; Different export types for different features as their needs may diverge
+          (:view-nodes :selected-nodes)
           (build-view-nodes-export db (:node-ids options))
           :graph-ontology
           (build-graph-ontology-export db {})

+ 4 - 2
src/main/frontend/components/content.cljs

@@ -81,7 +81,8 @@
                           (let [block-uuids (state/get-selection-block-ids)]
                             (shui/popup-hide!)
                             (shui/dialog-open!
-                             #(export/export-blocks block-uuids {:whiteboard? false}))))}
+                             #(export/export-blocks block-uuids {:whiteboard? false
+                                                                 :export-type :selected-nodes}))))}
       (t :content/copy-export-as))
 
      (shui/dropdown-menu-item
@@ -260,7 +261,8 @@
           {:key      "Copy as"
            :on-click (fn [_]
                        (shui/dialog-open!
-                        #(export/export-blocks [block-id] {:whiteboard? false})))}
+                        #(export/export-blocks [block-id] {:whiteboard? false
+                                                           :export-type :block})))}
           (t :content/copy-export-as))
 
          (when-not property-default-value?

+ 26 - 3
src/main/frontend/components/export.cljs

@@ -1,6 +1,7 @@
 (ns frontend.components.export
   (:require ["/frontend/utils" :as utils]
             [cljs-time.core :as t]
+            [cljs.pprint :as pprint]
             [frontend.config :as config]
             [frontend.context.i18n :refer [t]]
             [frontend.db :as db]
@@ -159,6 +160,20 @@
              current-repo block-uuids-or-page-name {:remove-options text-remove-options :other-options text-other-options})
       "")))
 
+(defn- <export-edn-helper
+  [root-block-uuids-or-page-uuid export-type]
+  (let [export-args (case export-type
+                      :page
+                      {:page-id [:block/uuid root-block-uuids-or-page-uuid]}
+                      :block
+                      {:block-id [:block/uuid (first root-block-uuids-or-page-uuid)]}
+                      :selected-nodes
+                      {:node-ids (mapv #(vector :block/uuid %) root-block-uuids-or-page-uuid)}
+                      {})]
+    (state/<invoke-db-worker :thread-api/export-edn
+                             (state/get-current-repo)
+                             (merge {:export-type export-type} export-args))))
+
 (defn- get-zoom-level
   [page-uuid]
   (let [uuid (:block/uuid (db/get-page page-uuid))
@@ -218,7 +233,7 @@
                  (reset! (::text-indent-style state) (state/get-export-block-text-indent-style))
                  (reset! (::text-other-options state) (state/get-export-block-text-other-options))
                  state)}
-  [state root-block-uuids-or-page-uuid {:keys [whiteboard?] :as options}]
+  [state root-block-uuids-or-page-uuid {:keys [whiteboard? export-type] :as options}]
   (let [tp @*export-block-type
         *text-other-options (::text-other-options state)
         *text-remove-options (::text-remove-options state)
@@ -244,10 +259,18 @@
                                    (reset! *content (export-helper root-block-uuids-or-page-uuid))))
          (when-not (seq? root-block-uuids-or-page-uuid)
            (ui/button "PNG"
-                      :class "w-20"
+                      :class "mr-4 w-20"
                       :on-click #(do (reset! *export-block-type :png)
                                      (reset! *content nil)
-                                     (get-image-blob root-block-uuids-or-page-uuid (merge options {:transparent-bg? false}) (fn [blob] (reset! *content blob))))))])
+                                     (get-image-blob root-block-uuids-or-page-uuid (merge options {:transparent-bg? false}) (fn [blob] (reset! *content blob))))))
+         (when (config/db-based-graph?)
+           (ui/button "EDN"
+                      :class "w-20"
+                      :on-click #(do (reset! *export-block-type :edn)
+                                     (p/let [result (<export-edn-helper root-block-uuids-or-page-uuid export-type)
+                                             pull-data (with-out-str (pprint/pprint result))]
+                                       (when-not (= :export-edn-error result)
+                                         (reset! *content pull-data))))))])
 
       (if (= :png tp)
         [:div.flex.items-center.justify-center.relative

+ 2 - 1
src/main/frontend/components/page_menu.cljs

@@ -132,7 +132,8 @@
             {:title   (t :export-page)
              :options {:on-click #(shui/dialog-open!
                                    (fn []
-                                     (export/export-blocks (:block/uuid page) {:whiteboard? whiteboard?}))
+                                     (export/export-blocks (:block/uuid page) {:whiteboard? whiteboard?
+                                                                               :export-type :page}))
                                    {:class "w-auto md:max-w-4xl max-h-[80vh] overflow-y-auto"})}})
 
           (when (util/electron?)