mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Merge pull request #5349 from penpot/palba-add-event-for-pdf
✨ Add export format info to export-shapes event
This commit is contained in:
commit
c607b61af6
4 changed files with 43 additions and 46 deletions
|
@ -7,6 +7,7 @@
|
|||
(ns app.main.data.exports.assets
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.data.persistence :as dwp]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
|
@ -247,6 +248,12 @@
|
|||
(rx/map #(clear-export-state @resource-id))
|
||||
(rx/take-until (rx/delay 6000 stopper))))))))
|
||||
|
||||
(defn request-export
|
||||
[{:keys [exports] :as params}]
|
||||
(if (= 1 (count exports))
|
||||
(request-simple-export (assoc params :export (first exports)))
|
||||
(request-multiple-export params)))
|
||||
|
||||
(defn retry-last-export
|
||||
[]
|
||||
(ptk/reify ::retry-last-export
|
||||
|
@ -256,3 +263,16 @@
|
|||
(when (seq params)
|
||||
(rx/of (request-multiple-export params)))))))
|
||||
|
||||
(defn export-shapes-event
|
||||
[exports origin]
|
||||
(let [types (reduce (fn [counts {:keys [type]}]
|
||||
(if (#{:png :pdf :svg :jpeg} type)
|
||||
(update counts type inc)
|
||||
counts))
|
||||
{:png 0, :pdf 0, :svg 0, :jpeg 0}
|
||||
exports)]
|
||||
(ptk/event
|
||||
::ev/event (merge types
|
||||
{::ev/name "export-shapes"
|
||||
::ev/origin origin
|
||||
:num-shapes (count exports)}))))
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
[app.common.colors :as clr]
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.exports.assets :as de]
|
||||
[app.main.data.modal :as modal]
|
||||
[app.main.refs :as refs]
|
||||
|
@ -23,7 +22,6 @@
|
|||
[app.util.i18n :as i18n :refer [tr c]]
|
||||
[app.util.strings :as ust]
|
||||
[cuerdas.core :as str]
|
||||
[potok.v2.core :as ptk]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def ^:private neutral-icon
|
||||
|
@ -59,13 +57,8 @@
|
|||
(fn [event]
|
||||
(dom/prevent-default event)
|
||||
(st/emit! (modal/hide)
|
||||
(de/request-multiple-export
|
||||
{:exports enabled-exports
|
||||
:cmd cmd})
|
||||
(ptk/event
|
||||
::ev/event {::ev/name "export-shapes"
|
||||
::ev/origin origin
|
||||
:num-shapes (count enabled-exports)})))
|
||||
(de/request-multiple-export {:exports enabled-exports :cmd cmd})
|
||||
(de/export-shapes-event enabled-exports origin)))
|
||||
|
||||
on-toggle-enabled
|
||||
(mf/use-fn
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
(:require-macros [app.main.style :as stl])
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.exports.assets :as de]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
|
@ -18,7 +17,6 @@
|
|||
[app.util.dom :as dom]
|
||||
[app.util.i18n :refer [tr c]]
|
||||
[app.util.keyboard :as kbd]
|
||||
[potok.v2.core :as ptk]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(mf/defc exports
|
||||
|
@ -63,15 +61,9 @@
|
|||
:object-id (-> shapes first :id)}
|
||||
(cond-> share-id (assoc :share-id share-id)))
|
||||
exports (mapv #(merge % defaults) @exports)]
|
||||
(if (= 1 (count exports))
|
||||
(st/emit!
|
||||
(de/request-simple-export {:export (first exports)})
|
||||
(ptk/event
|
||||
::ev/event {::ev/name "export-shapes" ::ev/origin "viewer" :num-shapes 1}))
|
||||
(st/emit!
|
||||
(de/request-multiple-export {:exports exports})
|
||||
(ptk/event
|
||||
::ev/event {::ev/name "export-shapes" ::ev/origin "viewer" :num-shapes (count exports)}))))))
|
||||
(st/emit!
|
||||
(de/request-export {:exports exports})
|
||||
(de/export-shapes-event exports "viewer")))))
|
||||
|
||||
add-export
|
||||
(mf/use-callback
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
(:require-macros [app.main.style :as stl])
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.exports.assets :as de]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
|
@ -21,7 +20,6 @@
|
|||
[app.util.dom :as dom]
|
||||
[app.util.i18n :refer [tr c]]
|
||||
[app.util.keyboard :as kbd]
|
||||
[potok.v2.core :as ptk]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def exports-attrs
|
||||
|
@ -66,21 +64,20 @@
|
|||
;; I can select multiple shapes all of them with no export settings and one of them with only one
|
||||
;; In that situation we must export it directly
|
||||
(if (and (= 1 (count shapes-with-exports)) (= 1 (-> shapes-with-exports first :exports count)))
|
||||
(let [shape (-> shapes-with-exports first)
|
||||
export (-> shape :exports first)
|
||||
sname (:name shape)
|
||||
suffix (:suffix export)
|
||||
defaults {:page-id page-id
|
||||
:file-id file-id
|
||||
:name sname
|
||||
:object-id (:id (first shapes-with-exports))}]
|
||||
(cond-> sname
|
||||
(some? suffix)
|
||||
(str suffix))
|
||||
(let [shape (-> shapes-with-exports first)
|
||||
export (-> shape :exports first)
|
||||
suffix (:suffix export)
|
||||
sname (cond-> (:name shape)
|
||||
(some? suffix)
|
||||
(str suffix))
|
||||
defaults {:page-id page-id
|
||||
:file-id file-id
|
||||
:name sname
|
||||
:object-id (:id (first shapes-with-exports))}
|
||||
full-export (merge export defaults)]
|
||||
(st/emit!
|
||||
(de/request-simple-export {:export (merge export defaults)})
|
||||
(ptk/event
|
||||
::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes 1})))
|
||||
(de/request-simple-export {:export full-export})
|
||||
(de/export-shapes-event [full-export] "workspace:sidebar")))
|
||||
(st/emit!
|
||||
(de/show-workspace-export-dialog {:selected (reverse ids) :origin "workspace:sidebar"})))
|
||||
|
||||
|
@ -92,16 +89,11 @@
|
|||
:name sname
|
||||
:object-id (first ids)}
|
||||
exports (mapv #(merge % defaults) exports)]
|
||||
(if (= 1 (count exports))
|
||||
(let [export (first exports)]
|
||||
(st/emit!
|
||||
(de/request-simple-export {:export export})
|
||||
(ptk/event
|
||||
::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes 1})))
|
||||
(st/emit!
|
||||
(de/request-multiple-export {:exports exports})
|
||||
(ptk/event
|
||||
::ev/event {::ev/name "export-shapes" ::ev/origin "workspace:sidebar" :num-shapes (count exports)})))))))
|
||||
|
||||
(st/emit!
|
||||
(de/request-export {:exports exports})
|
||||
(de/export-shapes-event exports "workspace:sidebar"))))))
|
||||
|
||||
|
||||
;; TODO: maybe move to specific events for avoid to have this logic here?
|
||||
add-export
|
||||
|
|
Loading…
Add table
Reference in a new issue