0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-25 14:11:33 -05:00

Merge pull request #3225 from penpot/alotor-demo-fixes

🐛 Fix problems with position absolute and code generation
This commit is contained in:
Eva Marco 2023-05-19 12:55:22 +02:00 committed by GitHub
commit 4c17d7d160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 27 deletions

View file

@ -162,7 +162,6 @@
(defn add-lines-positions (defn add-lines-positions
[parent layout-bounds layout-lines] [parent layout-bounds layout-lines]
(let [row? (ctl/row? parent) (let [row? (ctl/row? parent)
col? (ctl/col? parent) col? (ctl/col? parent)
auto-width? (ctl/auto-width? parent) auto-width? (ctl/auto-width? parent)
@ -410,6 +409,9 @@
reverse? (ctl/reverse? shape) reverse? (ctl/reverse? shape)
children (cond->> children (not reverse?) reverse) children (cond->> children (not reverse?) reverse)
;; Don't take into account absolute children
children (->> children (remove (comp ctl/layout-absolute? second)))
;; Creates the layout lines information ;; Creates the layout lines information
layout-lines layout-lines
(->> (init-layout-lines shape children layout-bounds) (->> (init-layout-lines shape children layout-bounds)

View file

@ -46,12 +46,16 @@
(defn format-padding-margin-shorthand (defn format-padding-margin-shorthand
[values] [values]
;; Values come in [p1 p2 p3 p4] ;; Values come in [p1 p2 p3 p4]
(let [[p1 p2 p3 p4] values] (let [[p1 p2 p3 p4] values
p1 (format-number p1)
p2 (format-number p2)
p3 (format-number p3)
p4 (format-number p4)]
(cond (cond
(apply = values) (= p1 p2 p3 p4)
{:p1 p1} {:p1 p1}
(= 4 (count (set values))) (= 4 (count (set [p1 p2 p3 p4])))
{:p1 p1 :p2 p2 :p3 p3 :p4 p4} {:p1 p1 :p2 p2 :p3 p3 :p4 p4}
(and (= p1 p3) (= p2 p4)) (and (= p1 p3) (= p2 p4))
@ -59,7 +63,6 @@
(and (not= p1 p3) (= p2 p4)) (and (not= p1 p3) (= p2 p4))
{:p1 p1 :p2 p2 :p3 p3} {:p1 p1 :p2 p2 :p3 p3}
:else :else
{:p1 p1 :p2 p2 :p3 p3 :p4 p4}))) {:p1 p1 :p2 p2 :p3 p3 :p4 p4})))
@ -71,7 +74,7 @@
(= sizing :fill) "100%" (= sizing :fill) "100%"
(= sizing :auto) "auto" (= sizing :auto) "auto"
(number? value) (format-pixels value) (number? value) (format-pixels value)
:else value))) :else value)))
(defn format-padding (defn format-padding
[padding-values type] [padding-values type]
@ -92,5 +95,5 @@
(let [row-gap (:row-gap gap-values) (let [row-gap (:row-gap gap-values)
column-gap (:column-gap gap-values)] column-gap (:column-gap gap-values)]
(if (= row-gap column-gap) (if (= row-gap column-gap)
(str/fmt "%spx" row-gap) (str/fmt "%spx" (format-number row-gap))
(str/fmt "%spx %spx" row-gap column-gap)))) (str/fmt "%spx %spx" (format-number row-gap) (format-number column-gap)))))

View file

@ -107,13 +107,13 @@
[:& copy-button {:data (copy-data shape :layout-align-content)}]]) [:& copy-button {:data (copy-data shape :layout-align-content)}]])
[:div.attributes-unit-row [:div.attributes-unit-row
[:div.attributes-label "Gap"] [:div.attributes-label "Gaps"]
(if (= (:row-gap (:layout-gap shape)) (:column-gap (:layout-gap shape))) (if (= (:row-gap (:layout-gap shape)) (:column-gap (:layout-gap shape)))
[:div.attributes-value [:div.attributes-value
[:span (str/capital (d/name (:row-gap (:layout-gap shape)))) "px"]] [:span (-> shape :layout-gap :row-gap fm/format-pixels)]]
[:div.attributes-value [:div.attributes-value
[:span.items (:row-gap (:layout-gap shape)) "px"] [:span.items (-> shape :layout-gap :row-gap fm/format-pixels)]
[:span (:column-gap (:layout-gap shape)) "px"]]) [:span (-> shape :layout-gap :column-gap fm/format-pixels)]])
[:& copy-button {:data (copy-data shape :layout-gap)}]] [:& copy-button {:data (copy-data shape :layout-gap)}]]
[:div.attributes-unit-row [:div.attributes-unit-row

View file

@ -72,7 +72,9 @@
page-id (:page-id (:query-params route)) page-id (:page-id (:query-params route))
flex-items (get-flex-elements page-id shapes from) flex-items (get-flex-elements page-id shapes from)
objects (get-objects from) objects (get-objects from)
shapes (map #(assoc % :flex-items flex-items) shapes) shapes (->> shapes
(map #(assoc % :parent (get objects (:parent-id %))))
(map #(assoc % :flex-items flex-items)))
style-code (-> (cg/generate-style-code @style-type shapes) style-code (-> (cg/generate-style-code @style-type shapes)
(format-code "css")) (format-code "css"))

View file

@ -10,6 +10,7 @@
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.text :as txt] [app.common.text :as txt]
[app.common.types.shape.layout :as ctl]
[app.main.ui.formats :as fmt] [app.main.ui.formats :as fmt]
[app.util.color :as uc] [app.util.color :as uc]
[cuerdas.core :as str])) [cuerdas.core :as str]))
@ -21,12 +22,6 @@
(if (= style :inner-shadow) "inset " "") (if (= style :inner-shadow) "inset " "")
(str/fmt "%spx %spx %spx %spx %s" offset-x offset-y blur spread css-color)))) (str/fmt "%spx %spx %spx %spx %s" offset-x offset-y blur spread css-color))))
(defn format-gap
[{row-gap :row-gap column-gap :column-gap}]
(if (= row-gap column-gap)
(str/fmt "%spx" row-gap)
(str/fmt "%spx %spx" row-gap column-gap)))
(defn fill-color->background (defn fill-color->background
[fill] [fill]
(uc/color->background {:color (:fill-color fill) (uc/color->background {:color (:fill-color fill)
@ -58,10 +53,15 @@
(str/format "%spx %s %s" width style (uc/color->background color))))) (str/format "%spx %s %s" width style (uc/color->background color)))))
(defn format-position [_ shape] (defn format-position [_ shape]
(cond (let [relative? (cph/frame-shape? shape)
(cph/frame-shape? shape) "relative" absolute? (or (empty? (:flex-items shape))
(empty? (:flex-items shape)) "absolute" (and (ctl/any-layout? (:parent shape)) (ctl/layout-absolute? shape)))]
:else "static")) (cond
absolute? "absolute"
relative? "relative"
;; static is default value in css
:else nil)))
(defn get-size (defn get-size
[type values] [type values]
@ -80,7 +80,8 @@
{:position {:props [:type] {:position {:props [:type]
:to-prop {:type "position"} :to-prop {:type "position"}
:format {:type format-position}} :format {:type format-position}}
:layout {:props (if (empty? (:flex-items shape)) :layout {:props (if (or (empty? (:flex-items shape))
(ctl/layout-absolute? shape))
[:width :height :x :y :radius :rx :r1] [:width :height :x :y :radius :rx :r1]
[:width :height :radius :rx :r1]) [:width :height :radius :rx :r1])
:to-prop {:x "left" :to-prop {:x "left"
@ -89,7 +90,7 @@
:rx "border-radius" :rx "border-radius"
:r1 "border-radius"} :r1 "border-radius"}
:format {:rotation #(str/fmt "rotate(%sdeg)" %) :format {:rotation #(str/fmt "rotate(%sdeg)" %)
:r1 #(apply str/fmt "%spx, %spx, %spx, %spx" %) :r1 #(apply str/fmt "%spx %spx %spx %spx" %)
:width #(get-size :width %) :width #(get-size :width %)
:height #(get-size :height %)} :height #(get-size :height %)}
:multi {:r1 [:r1 :r2 :r3 :r4]}} :multi {:r1 [:r1 :r2 :r3 :r4]}}
@ -124,7 +125,7 @@
:layout-align-items d/name :layout-align-items d/name
:layout-justify-content d/name :layout-justify-content d/name
:layout-wrap-type d/name :layout-wrap-type d/name
:layout-gap format-gap :layout-gap fmt/format-gap
:layout-padding fmt/format-padding}}}) :layout-padding fmt/format-padding}}})
(def style-text (def style-text