From 8952cb4e000d0969047253d270edf312726cf995 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 14 Jun 2021 16:12:51 +0200 Subject: [PATCH] :sparkles: Adds constraints to export/import --- frontend/src/app/main/ui/shapes/export.cljs | 21 +++++++++++++-------- frontend/src/app/util/import/parser.cljc | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/main/ui/shapes/export.cljs b/frontend/src/app/main/ui/shapes/export.cljs index 5fcdb9153..a74740040 100644 --- a/frontend/src/app/main/ui/shapes/export.cljs +++ b/frontend/src/app/main/ui/shapes/export.cljs @@ -70,6 +70,11 @@ (obj/set! "penpot:center-x" (-> center :x str)) (obj/set! "penpot:center-y" (-> center :y str)) + ;; Constraints + (add! :constraints-h) + (add! :constraints-v) + (add! :fixed-scroll) + (cond-> (and rect? (some? (:r1 shape))) (-> (add! :r1) (add! :r2) @@ -105,14 +110,14 @@ (mf/defc export-page [{:keys [options]}] - [:> "penpot:page" #js {} - (let [saved-grids (get options :saved-grids)] - (when-not (empty? saved-grids) - (let [parse-grid - (fn [[type params]] - {:type type :params params}) - grids (->> saved-grids (mapv parse-grid))] - [:& export-grid-data {:grids grids}])))]) + (let [saved-grids (get options :saved-grids)] + (when-not (empty? saved-grids) + (let [parse-grid + (fn [[type params]] + {:type type :params params}) + grids (->> saved-grids (mapv parse-grid))] + [:> "penpot:page" #js {} + [:& export-grid-data {:grids grids}]])))) (mf/defc export-data [{:keys [shape]}] diff --git a/frontend/src/app/util/import/parser.cljc b/frontend/src/app/util/import/parser.cljc index 8609e3ed1..2f3857b6a 100644 --- a/frontend/src/app/util/import/parser.cljc +++ b/frontend/src/app/util/import/parser.cljc @@ -267,7 +267,10 @@ flip-y (get-meta node :flip-y str->bool) proportion (get-meta node :proportion d/parse-double) proportion-lock (get-meta node :proportion-lock str->bool) - rotation (get-meta node :rotation d/parse-double)] + rotation (get-meta node :rotation d/parse-double) + constraints-h (get-meta node :constraints-h keyword) + constraints-v (get-meta node :constraints-v keyword) + fixed-scroll (get-meta node :fixed-scroll str->bool)] (-> props (assoc :name name) @@ -279,7 +282,16 @@ (assoc :flip-y flip-y) (assoc :proportion proportion) (assoc :proportion-lock proportion-lock) - (assoc :rotation rotation)))) + (assoc :rotation rotation) + + (cond-> (some? constraints-h) + (assoc :constraints-h constraints-h)) + + (cond-> (some? constraints-v) + (assoc :constraints-v constraints-v)) + + (cond-> (some? fixed-scroll) + (assoc :fixed-scroll fixed-scroll))))) (defn add-position [props type node svg-data]