enhance: persistent "Copy As" options

pull/2708/head
Tienson Qin 2021-08-24 23:11:49 +08:00
parent 81e93cbd5e
commit e2abf01deb
3 changed files with 25 additions and 18 deletions

View File

@ -76,8 +76,8 @@
[state root-block-ids]
(let [current-repo (state/get-current-repo)
type (rum/react *export-block-type)
text-indent-style (rum/react (state/get-export-block-text-indent-style))
text-remove-options (rum/react (state/get-export-block-text-remove-options))
text-indent-style (state/sub :copy/export-block-text-indent-style)
text-remove-options (state/sub :copy/export-block-text-remove-options)
copied? (::copied? state)
content
(case type
@ -112,7 +112,7 @@
:visibility (if (= :text type) "visible" "hidden")}
:on-change (fn [e]
(let [value (util/evalue e)]
(reset! (state/get-export-block-text-indent-style) value)))}
(state/set-export-block-text-indent-style! value)))}
(for [{:keys [label value selected]} options]
[:option (cond->
{:key label
@ -124,11 +124,8 @@
(ui/checkbox {:style {:margin-right 6
:visibility (if (= :text type) "visible" "hidden")}
:checked (contains? text-remove-options :page-ref)
:on-change (fn [e] (if (util/echecked? e)
(swap! (state/get-export-block-text-remove-options)
#(conj % :page-ref))
(swap! (state/get-export-block-text-remove-options)
#(disj % :page-ref))))})
:on-change (fn [e]
(state/update-export-block-text-remove-options! e :page-ref))})
[:div
{:style {:visibility (if (= :text type) "visible" "hidden")}}
@ -137,11 +134,8 @@
:margin-left 10
:visibility (if (= :text type) "visible" "hidden")}
:checked (contains? text-remove-options :emphasis)
:on-change (fn [e] (if (util/echecked? e)
(swap! (state/get-export-block-text-remove-options)
#(conj % :emphasis))
(swap! (state/get-export-block-text-remove-options)
#(disj % :emphasis))))})
:on-change (fn [e]
(state/update-export-block-text-remove-options! e :emphasis))})
[:div
{:style {:visibility (if (= :text type) "visible" "hidden")}}

View File

@ -1088,8 +1088,8 @@
top-level-block-uuids (mapv :block/uuid (filterv #(not (vector? %)) tree))
exported-md-contents (export/export-blocks-as-markdown
repo top-level-block-uuids
@(state/get-export-block-text-indent-style)
(into [] @(state/get-export-block-text-remove-options)))]
(state/get-export-block-text-indent-style)
(into [] (state/get-export-block-text-remove-options)))]
[exported-md-contents tree]))
(defn copy-selection-blocks

View File

@ -150,9 +150,10 @@
;; 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 #{})
:copy/export-block-text-indent-style (or (storage/get :copy/export-block-text-indent-style)
"dashes")
:copy/export-block-text-remove-options (or (storage/get :copy/export-block-text-remove-options)
#{})
:date-picker/date nil
:view/components {}})))
@ -1385,9 +1386,21 @@
(defn get-export-block-text-indent-style []
(:copy/export-block-text-indent-style @state))
(defn set-export-block-text-indent-style!
[v]
(set-state! :copy/export-block-text-indent-style v)
(storage/set :copy/export-block-text-indent-style v))
(defn get-export-block-text-remove-options []
(:copy/export-block-text-remove-options @state))
(defn update-export-block-text-remove-options!
[e k]
(let [f (if (util/echecked? e) conj disj)]
(update-state! :copy/export-block-text-remove-options
#(f % k))
(storage/set :copy/export-block-text-remove-options
(get-export-block-text-remove-options))))
(defn set-editor-args!
[args]