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
This commit is contained in:
Gabriel Horner
2025-04-04 11:07:05 -04:00
parent cf114803ff
commit 445be61fcf
4 changed files with 34 additions and 7 deletions

View File

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