mirror of
https://github.com/penpot/penpot.git
synced 2026-03-23 11:50:49 +01:00
Merge pull request #4223 from penpot/niwinz-staging-bugfix-4
🐛 Several bugfixes and optimizations
This commit is contained in:
@@ -716,20 +716,19 @@
|
||||
|
||||
(defn name
|
||||
"Improved version of name that won't fail if the input is not a keyword"
|
||||
([maybe-keyword] (name maybe-keyword nil))
|
||||
([maybe-keyword default-value]
|
||||
(cond
|
||||
(keyword? maybe-keyword)
|
||||
(c/name maybe-keyword)
|
||||
[maybe-keyword]
|
||||
(cond
|
||||
(nil? maybe-keyword)
|
||||
nil
|
||||
|
||||
(string? maybe-keyword)
|
||||
maybe-keyword
|
||||
(keyword? maybe-keyword)
|
||||
(c/name maybe-keyword)
|
||||
|
||||
(nil? maybe-keyword) default-value
|
||||
(string? maybe-keyword)
|
||||
maybe-keyword
|
||||
|
||||
:else
|
||||
(or default-value
|
||||
(str maybe-keyword)))))
|
||||
:else
|
||||
(str maybe-keyword)))
|
||||
|
||||
(defn prefix-keyword
|
||||
"Given a keyword and a prefix will return a new keyword with the prefix attached
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
[app.common.schema :as sm]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.set :as set]
|
||||
[cuerdas.core :as str]))
|
||||
@@ -741,22 +740,6 @@
|
||||
(d/seek root-frame?)
|
||||
:id))
|
||||
|
||||
(defn comparator-layout-z-index
|
||||
[[idx-a child-a] [idx-b child-b]]
|
||||
(cond
|
||||
(> (ctl/layout-z-index child-a) (ctl/layout-z-index child-b)) 1
|
||||
(< (ctl/layout-z-index child-a) (ctl/layout-z-index child-b)) -1
|
||||
(< idx-a idx-b) 1
|
||||
(> idx-a idx-b) -1
|
||||
:else 0))
|
||||
|
||||
(defn sort-layout-children-z-index
|
||||
[children]
|
||||
(->> children
|
||||
(d/enumerate)
|
||||
(sort comparator-layout-z-index)
|
||||
(mapv second)))
|
||||
|
||||
(defn common-parent-frame
|
||||
"Search for the common frame for the selected shapes. Otherwise returns the root frame"
|
||||
[objects selected]
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.geom.shapes.grid-layout.areas :as sga]
|
||||
[app.common.math :as mth]
|
||||
[app.common.schema :as sm]
|
||||
@@ -47,7 +48,8 @@
|
||||
#{:flex :grid})
|
||||
|
||||
(def flex-direction-types
|
||||
#{:row :reverse-row :row-reverse :column :reverse-column :column-reverse}) ;;TODO remove reverse-column and reverse-row after script
|
||||
;;TODO remove reverse-column and reverse-row after script
|
||||
#{:row :reverse-row :row-reverse :column :reverse-column :column-reverse})
|
||||
|
||||
(def grid-direction-types
|
||||
#{:row :column})
|
||||
@@ -128,7 +130,7 @@
|
||||
(def grid-cell-justify-self-types
|
||||
#{:auto :start :center :end :stretch})
|
||||
|
||||
(sm/define! ::grid-cell
|
||||
(sm/def! ::grid-cell
|
||||
[:map {:title "GridCell"}
|
||||
[:id ::sm/uuid]
|
||||
[:area-name {:optional true} :string]
|
||||
@@ -142,7 +144,7 @@
|
||||
[:shapes
|
||||
[:vector {:gen/max 1} ::sm/uuid]]])
|
||||
|
||||
(sm/define! ::grid-track
|
||||
(sm/def! ::grid-track
|
||||
[:map {:title "GridTrack"}
|
||||
[:type [::sm/one-of grid-track-types]]
|
||||
[:value {:optional true} [:maybe ::sm/safe-number]]])
|
||||
@@ -197,14 +199,14 @@
|
||||
([objects id]
|
||||
(flex-layout? (get objects id)))
|
||||
([shape]
|
||||
(and (= :frame (:type shape))
|
||||
(and (cfh/frame-shape? shape)
|
||||
(= :flex (:layout shape)))))
|
||||
|
||||
(defn grid-layout?
|
||||
([objects id]
|
||||
(grid-layout? (get objects id)))
|
||||
([shape]
|
||||
(and (= :frame (:type shape))
|
||||
(and (cfh/frame-shape? shape)
|
||||
(= :grid (:layout shape)))))
|
||||
|
||||
(defn any-layout?
|
||||
@@ -212,7 +214,10 @@
|
||||
(any-layout? (get objects id)))
|
||||
|
||||
([shape]
|
||||
(or (flex-layout? shape) (grid-layout? shape))))
|
||||
(and (cfh/frame-shape? shape)
|
||||
(let [layout (:layout shape)]
|
||||
(or (= :flex layout)
|
||||
(= :grid layout))))))
|
||||
|
||||
(defn flex-layout-immediate-child? [objects shape]
|
||||
(let [parent-id (:parent-id shape)
|
||||
@@ -262,20 +267,21 @@
|
||||
(defn inside-layout?
|
||||
"Check if the shape is inside a layout"
|
||||
[objects shape]
|
||||
|
||||
(loop [current-id (:id shape)]
|
||||
(let [current (get objects current-id)]
|
||||
(loop [current-id (dm/get-prop shape :id)]
|
||||
(let [current (get objects current-id)
|
||||
parent-id (dm/get-prop current :parent-id)]
|
||||
(cond
|
||||
(or (nil? current) (= current-id (:parent-id current)))
|
||||
(or (nil? current) (= current-id parent-id))
|
||||
false
|
||||
|
||||
(= :frame (:type current))
|
||||
(cfh/frame-shape? current-id)
|
||||
(:layout current)
|
||||
|
||||
:else
|
||||
(recur (:parent-id current))))))
|
||||
(recur parent-id)))))
|
||||
|
||||
(defn wrap? [{:keys [layout-wrap-type]}]
|
||||
(defn wrap?
|
||||
[{:keys [layout-wrap-type]}]
|
||||
(= layout-wrap-type :wrap))
|
||||
|
||||
(defn fill-width?
|
||||
@@ -536,6 +542,22 @@
|
||||
([shape]
|
||||
(or (:layout-item-z-index shape) 0)))
|
||||
|
||||
(defn- comparator-layout-z-index
|
||||
[[idx-a child-a] [idx-b child-b]]
|
||||
(cond
|
||||
(> (layout-z-index child-a) (layout-z-index child-b)) 1
|
||||
(< (layout-z-index child-a) (layout-z-index child-b)) -1
|
||||
(< idx-a idx-b) 1
|
||||
(> idx-a idx-b) -1
|
||||
:else 0))
|
||||
|
||||
(defn sort-layout-children-z-index
|
||||
[children]
|
||||
(->> children
|
||||
(d/enumerate)
|
||||
(sort comparator-layout-z-index)
|
||||
(mapv second)))
|
||||
|
||||
(defn change-h-sizing?
|
||||
[frame-id objects children-ids]
|
||||
(and (flex-layout? objects frame-id)
|
||||
|
||||
Reference in New Issue
Block a user