Browse Source

move copy-options to global state

rcmerci 4 years ago
parent
commit
75e9cef533

+ 7 - 10
src/main/frontend/components/export.cljs

@@ -70,17 +70,14 @@
                                 {:label "no-indent"
                                  :selected false}])
 
-(def *export-block-text-indent-style (atom "dashes"))
-(def *export-block-text-remove-options (atom #{}))
-
 (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)
-        text-remove-options (rum/react *export-block-text-remove-options)
+        text-indent-style (rum/react (state/get-export-block-text-indent-style))
+        text-remove-options (rum/react (state/get-export-block-text-remove-options))
         copied? (::copied? state)
         content
         (case type
@@ -115,7 +112,7 @@
                             :visibility (if (= :text type) "visible" "hidden")}
                 :on-change (fn [e]
                              (let [value (util/evalue e)]
-                               (reset! *export-block-text-indent-style value)))}
+                               (reset! (state/get-export-block-text-indent-style) value)))}
                (for [{:keys [label value selected]} options]
                  [:option (cond->
                            {:key   label
@@ -128,9 +125,9 @@
                                :visibility (if (= :text type) "visible" "hidden")}
                        :checked (contains? text-remove-options :page-ref)
                        :on-change (fn [e] (if (util/echecked? e)
-                                            (swap! *export-block-text-remove-options
+                                            (swap! (state/get-export-block-text-remove-options)
                                                    #(conj % :page-ref))
-                                            (swap! *export-block-text-remove-options
+                                            (swap! (state/get-export-block-text-remove-options)
                                                    #(disj % :page-ref))))})
 
          [:div
@@ -141,9 +138,9 @@
                                :visibility (if (= :text type) "visible" "hidden")}
                        :checked (contains? text-remove-options :emphasis)
                        :on-change (fn [e] (if (util/echecked? e)
-                                            (swap! *export-block-text-remove-options
+                                            (swap! (state/get-export-block-text-remove-options)
                                                    #(conj % :emphasis))
-                                            (swap! *export-block-text-remove-options
+                                            (swap! (state/get-export-block-text-remove-options)
                                                    #(disj % :emphasis))))})
 
          [:div

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

@@ -1076,8 +1076,8 @@
         top-level-block-uuids (mapv :block/uuid (filterv #(not (vector? %)) tree))
         exported-md-contents (mapv #(export/export-blocks-as-markdown
                                      repo %
-                                     @frontend.components.export/*export-block-text-indent-style
-                                     (into [] @frontend.components.export/*export-block-text-remove-options))
+                                     @(state/get-export-block-text-indent-style)
+                                     (into [] @(state/get-export-block-text-remove-options)))
                                    top-level-block-uuids)]
     [(string/join "\n" (mapv string/trim-newline exported-md-contents)) tree]))
 

+ 10 - 0
src/main/frontend/state.cljs

@@ -140,6 +140,9 @@
       ;; copied blocks
       :copy/blocks {:copy/content nil :copy/block-tree nil}
 
+      :copy/export-block-text-indent-style  (atom "dashes")
+      :copy/export-block-text-remove-options (atom #{})
+
       :date-picker/date nil
 
       :view/components {}})))
@@ -1346,6 +1349,13 @@
   [content ids]
   (set-state! :copy/blocks {:copy/content content :copy/block-tree ids}))
 
+(defn get-export-block-text-indent-style []
+  (:copy/export-block-text-indent-style @state))
+
+(defn get-export-block-text-remove-options []
+  (:copy/export-block-text-remove-options @state))
+
+
 (defn set-editor-args!
   [args]
   (set-state! :editor/args args))