Browse Source

update block-level export ui

rcmerci 4 năm trước cách đây
mục cha
commit
b167ae4943

+ 5 - 10
src/main/frontend/components/content.cljs

@@ -19,6 +19,7 @@
             [cljs.pprint :as pprint]
             [frontend.handler.notification :as notification]
             [frontend.components.editor :as editor]
+            [frontend.components.export :as export]
             [frontend.context.i18n :as i18n]
             [frontend.text :as text]
             [frontend.handler.page :as page-handler]))
@@ -172,17 +173,11 @@
 
           (block-template block-id)
 
-          ;; (ui/menu-link
-          ;;  {:key "Make template"
-          ;;   :on-click (fn [_e]
-          ;;               (editor-handler/copy-block-ref! block-id))}
-          ;;  "Make template")
-
           (ui/menu-link
-           {:key "Copy as text"
-            :on-click (fn [_e]
-                        (export-handler/copy-block! block-id))}
-           "Copy as TEXT")
+           {:key "Export"
+            :on-click (fn [_]
+                        (state/set-modal! #(export/export-blocks block-id)))}
+           "Export")
 
           (ui/menu-link
            {:key "Copy as JSON"

+ 43 - 0
src/main/frontend/components/export.cljs

@@ -65,3 +65,46 @@
          [:a#export-page-as-markdown.hidden]
          [:a#export-page-as-opml.hidden]
          [:a#convert-markdown-to-unordered-list-or-heading.hidden]]))))
+
+(def *export-block-type (atom :text))
+
+(def text-indent-style-options [{:label "dash"
+                                 :selected false}
+                                {:label "space"
+                                 :selected false}
+                                {:label "no-indent"
+                                 :selected false}])
+
+(def *export-block-text-indent-style (atom "dash"))
+
+(rum/defcs export-blocks
+  < rum/reactive
+  (rum/local false ::copied?)
+  [state root-block-id]
+  (let [current-repo (state/get-current-repo)
+        type (rum/react *export-block-type)
+        text-indent-style (rum/react *export-block-text-indent-style)
+        copied? (::copied? state)
+        content
+        (case type
+          :text (export/export-blocks-as-markdown current-repo root-block-id text-indent-style)
+          :opml (export/export-blocks-as-opml current-repo root-block-id)
+          (export/export-blocks-as-markdown current-repo root-block-id text-indent-style))]
+    [:div.export.w-96.resize
+     (ui/button "Text"
+                :on-click #(reset! *export-block-type :text))
+     (ui/button "OPML"
+                :on-click #(reset! *export-block-type :opml))
+     [:textarea.overflow-y-auto.h-96 {:value content}]
+     (when (and (:not-impl-yet 0)
+                (= :text type))
+       (let [options (->> text-indent-style-options
+                          (mapv (fn [opt]
+                                  (if (= text-indent-style (:label opt))
+                                    (assoc opt :selected true)
+                                    opt))))]
+         (ui/select options #(reset! *export-block-text-indent-style %))))
+     (ui/button (if @copied? "Copied to clipboard!" "Copy to clipboard")
+                :on-click (fn []
+                            (util/copy-to-clipboard! content)
+                            (reset! copied? true)))]))

+ 3 - 9
src/main/frontend/handler/export.cljs

@@ -67,12 +67,6 @@
    (outliner-tree/blocks->vec-tree (str (:block/uuid block)))
    (outliner-file/tree->file-content {:init-level 1})))
 
-(defn copy-block!
-  [block-id]
-  (when-let [block (db/pull [:block/uuid block-id])]
-    (let [content (:block/content block)]
-      (common-handler/copy-to-clipboard-without-id-property! (:block/format block) content))))
-
 (defn copy-block-as-json!
   [block-id]
   (when-let [repo (state/get-current-repo)]
@@ -454,7 +448,7 @@
                                            (clj->js (f (first names)))))]))))
          (remove nil?))))
 
-(defn- export-blocks-as-opml
+(defn export-blocks-as-opml
   [repo root-block-uuid]
   (let [get-page&block-refs-by-query-aux (get-embed-and-refs-blocks-pages-aux)
         f #(get-page&block-refs-by-query repo % get-page&block-refs-by-query-aux {:is-block? true})
@@ -468,8 +462,8 @@
                    "untitled"
                    (js/JSON.stringify (clj->js refs)))))
 
-(defn- export-blocks-as-markdown
-  [repo root-block-uuid]
+(defn export-blocks-as-markdown
+  [repo root-block-uuid indent-style]
   (let [get-page&block-refs-by-query-aux (get-embed-and-refs-blocks-pages-aux)
         f #(get-page&block-refs-by-query repo % get-page&block-refs-by-query-aux {:is-block? true})
         root-block (db/entity [:block/uuid root-block-uuid])