mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 21:06:40 +02:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
0cad1a1e7e
12 changed files with 105 additions and 106 deletions
|
@ -183,7 +183,7 @@
|
||||||
|
|
||||||
(defmethod ig/prep-key ::gc-task
|
(defmethod ig/prep-key ::gc-task
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(merge {:max-age (dt/duration {:days 2})}
|
(merge {:max-age (dt/duration {:days 15})}
|
||||||
(d/without-nils cfg)))
|
(d/without-nils cfg)))
|
||||||
|
|
||||||
(defmethod ig/init-key ::gc-task
|
(defmethod ig/init-key ::gc-task
|
||||||
|
|
|
@ -261,20 +261,12 @@
|
||||||
|
|
||||||
(defn select-frames
|
(defn select-frames
|
||||||
[objects]
|
[objects]
|
||||||
(let [root (get objects uuid/zero)
|
(let [lookup #(get objects %)
|
||||||
loopfn (fn loopfn [ids]
|
frame? #(= :frame (:type %))
|
||||||
(let [id (first ids)
|
xform (comp (map lookup)
|
||||||
obj (get objects id)]
|
(filter frame?))]
|
||||||
(cond
|
(->> (:shapes (lookup uuid/zero))
|
||||||
(or (nil? id) (nil? obj))
|
(into [] xform))))
|
||||||
nil
|
|
||||||
|
|
||||||
(= :frame (:type obj))
|
|
||||||
(lazy-seq (cons obj (loopfn (rest ids))))
|
|
||||||
|
|
||||||
:else
|
|
||||||
(lazy-seq (loopfn (rest ids))))))]
|
|
||||||
(loopfn (:shapes root))))
|
|
||||||
|
|
||||||
(defn clone-object
|
(defn clone-object
|
||||||
"Gets a copy of the object and all its children, with new ids
|
"Gets a copy of the object and all its children, with new ids
|
||||||
|
|
|
@ -506,7 +506,6 @@
|
||||||
stopper (rx/filter ms/mouse-up? stream)]
|
stopper (rx/filter ms/mouse-up? stream)]
|
||||||
(when-not (empty? selected)
|
(when-not (empty? selected)
|
||||||
(->> ms/mouse-position
|
(->> ms/mouse-position
|
||||||
(rx/take-until stopper)
|
|
||||||
(rx/map #(gpt/to-vec initial %))
|
(rx/map #(gpt/to-vec initial %))
|
||||||
(rx/map #(gpt/length %))
|
(rx/map #(gpt/length %))
|
||||||
(rx/filter #(> % 1))
|
(rx/filter #(> % 1))
|
||||||
|
@ -519,7 +518,9 @@
|
||||||
(rx/of (start-move-duplicate initial)
|
(rx/of (start-move-duplicate initial)
|
||||||
(dws/duplicate-selected false))
|
(dws/duplicate-selected false))
|
||||||
;; Otherwise just plain old move
|
;; Otherwise just plain old move
|
||||||
(rx/of (start-move initial selected)))))))))))
|
(rx/of (start-move initial selected)))))
|
||||||
|
(rx/take-until stopper)))))))
|
||||||
|
|
||||||
|
|
||||||
(defn- start-move-duplicate
|
(defn- start-move-duplicate
|
||||||
[from-position]
|
[from-position]
|
||||||
|
@ -560,7 +561,6 @@
|
||||||
delta)))
|
delta)))
|
||||||
|
|
||||||
position (->> ms/mouse-position
|
position (->> ms/mouse-position
|
||||||
(rx/take-until stopper)
|
|
||||||
(rx/with-latest-from ms/mouse-position-shift)
|
(rx/with-latest-from ms/mouse-position-shift)
|
||||||
(rx/map #(fix-axis %)))
|
(rx/map #(fix-axis %)))
|
||||||
|
|
||||||
|
@ -579,7 +579,8 @@
|
||||||
(->> position
|
(->> position
|
||||||
(rx/with-latest vector snap-delta)
|
(rx/with-latest vector snap-delta)
|
||||||
(rx/map snap/correct-snap-point)
|
(rx/map snap/correct-snap-point)
|
||||||
(rx/map set-local-displacement))
|
(rx/map set-local-displacement)
|
||||||
|
(rx/take-until stopper))
|
||||||
|
|
||||||
(rx/of (set-modifiers ids)
|
(rx/of (set-modifiers ids)
|
||||||
(apply-modifiers ids)
|
(apply-modifiers ids)
|
||||||
|
|
|
@ -219,7 +219,7 @@
|
||||||
(l/derived :options workspace-page))
|
(l/derived :options workspace-page))
|
||||||
|
|
||||||
(def workspace-frames
|
(def workspace-frames
|
||||||
(l/derived cp/select-frames workspace-page-objects))
|
(l/derived cp/select-frames workspace-page-objects =))
|
||||||
|
|
||||||
(def workspace-editor
|
(def workspace-editor
|
||||||
(l/derived :workspace-editor st/state))
|
(l/derived :workspace-editor st/state))
|
||||||
|
|
|
@ -162,5 +162,12 @@
|
||||||
(obj/set! "onKeyDown" handle-key-down)
|
(obj/set! "onKeyDown" handle-key-down)
|
||||||
(obj/set! "onBlur" handle-blur))]
|
(obj/set! "onBlur" handle-blur))]
|
||||||
|
|
||||||
|
(mf/use-effect
|
||||||
|
(mf/deps value-str)
|
||||||
|
(fn []
|
||||||
|
(when-let [input-node (mf/ref-val ref)]
|
||||||
|
(when-not (dom/active? input-node)
|
||||||
|
(dom/set-value! input-node value-str)))))
|
||||||
|
|
||||||
[:> :input props]))
|
[:> :input props]))
|
||||||
|
|
||||||
|
|
|
@ -522,7 +522,7 @@
|
||||||
[:li.feedback {:on-click (partial on-click :settings-feedback)}
|
[:li.feedback {:on-click (partial on-click :settings-feedback)}
|
||||||
[:span.icon i/msg-info]
|
[:span.icon i/msg-info]
|
||||||
[:span.text (tr "labels.give-feedback")]
|
[:span.text (tr "labels.give-feedback")]
|
||||||
[:span.primary-badge "BETA"]])]]]
|
])]]]
|
||||||
|
|
||||||
(when (and team profile)
|
(when (and team profile)
|
||||||
[:& comments-section {:profile profile
|
[:& comments-section {:profile profile
|
||||||
|
|
|
@ -289,8 +289,8 @@
|
||||||
|
|
||||||
(when (contains? @cf/flags :user-feedback)
|
(when (contains? @cf/flags :user-feedback)
|
||||||
[:li.feedback {:on-click (st/emitf (rt/nav :settings-feedback))}
|
[:li.feedback {:on-click (st/emitf (rt/nav :settings-feedback))}
|
||||||
[:span (tr "labels.give-feedback")]
|
[:span (tr "labels.give-feedback")]])
|
||||||
[:span.primary-badge "ALPHA"]])
|
|
||||||
]]]))
|
]]]))
|
||||||
|
|
||||||
;; --- Header Component
|
;; --- Header Component
|
||||||
|
|
|
@ -64,7 +64,6 @@
|
||||||
(fn [value]
|
(fn [value]
|
||||||
(on-change (assoc-in grid keys-path value))))
|
(on-change (assoc-in grid keys-path value))))
|
||||||
|
|
||||||
;; TODO: remove references to :auto
|
|
||||||
handle-change-size
|
handle-change-size
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps grid)
|
(mf/deps grid)
|
||||||
|
@ -75,7 +74,6 @@
|
||||||
(-> (gg/calculate-default-item-length frame-length margin gutter)
|
(-> (gg/calculate-default-item-length frame-length margin gutter)
|
||||||
(mth/precision 2))
|
(mth/precision 2))
|
||||||
item-length)]
|
item-length)]
|
||||||
|
|
||||||
(-> grid
|
(-> grid
|
||||||
(update :params assoc :size size :item-length item-length)
|
(update :params assoc :size size :item-length item-length)
|
||||||
(on-change)))))
|
(on-change)))))
|
||||||
|
|
|
@ -20,13 +20,14 @@
|
||||||
[app.util.i18n :as i18n :refer [tr]]
|
[app.util.i18n :as i18n :refer [tr]]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
(def measure-attrs [:proportion-lock
|
(def measure-attrs
|
||||||
:width :height
|
[:proportion-lock
|
||||||
:x :y
|
:width :height
|
||||||
:rotation
|
:x :y
|
||||||
:rx :ry
|
:rotation
|
||||||
:r1 :r2 :r3 :r4
|
:rx :ry
|
||||||
:selrect])
|
:r1 :r2 :r3 :r4
|
||||||
|
:selrect])
|
||||||
|
|
||||||
(defn- attr->string [attr values]
|
(defn- attr->string [attr values]
|
||||||
(let [value (attr values)]
|
(let [value (attr values)]
|
||||||
|
|
|
@ -295,7 +295,7 @@
|
||||||
|
|
||||||
(when show-grids?
|
(when show-grids?
|
||||||
[:& frame-grid/frame-grid
|
[:& frame-grid/frame-grid
|
||||||
{:zoom zoom}])
|
{:zoom zoom :selected selected :transform transform}])
|
||||||
|
|
||||||
(when show-pixel-grid?
|
(when show-pixel-grid?
|
||||||
[:& widgets/pixel-grid
|
[:& widgets/pixel-grid
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
:height (:height frame)
|
:height (:height frame)
|
||||||
:fill (str "url(#" grid-id ")")}]]))
|
:fill (str "url(#" grid-id ")")}]]))
|
||||||
|
|
||||||
(mf/defc layout-grid [{:keys [key frame grid]}]
|
(mf/defc layout-grid
|
||||||
|
[{:keys [key frame grid]}]
|
||||||
(let [{color-value :color color-opacity :opacity} (-> grid :params :color)
|
(let [{color-value :color color-opacity :opacity} (-> grid :params :color)
|
||||||
;; Support for old color format
|
;; Support for old color format
|
||||||
color-value (or color-value (:value (get-in grid [:params :color :value])))
|
color-value (or color-value (:value (get-in grid [:params :color :value])))
|
||||||
|
@ -56,42 +57,37 @@
|
||||||
:strokeOpacity color-opacity
|
:strokeOpacity color-opacity
|
||||||
:fill "none"})]
|
:fill "none"})]
|
||||||
[:g.grid
|
[:g.grid
|
||||||
(for [{:keys [x y width height]} (gg/grid-areas frame grid)]
|
(for [{:keys [x y width height] :as area} (gg/grid-areas frame grid)]
|
||||||
(do
|
[:rect {:key (str key "-" x "-" y)
|
||||||
[:rect {:key (str key "-" x "-" y)
|
:x (mth/round x)
|
||||||
:x (mth/round x)
|
:y (mth/round y)
|
||||||
:y (mth/round y)
|
:width (- (mth/round (+ x width)) (mth/round x))
|
||||||
:width (- (mth/round (+ x width)) (mth/round x))
|
:height (- (mth/round (+ y height)) (mth/round y))
|
||||||
:height (- (mth/round (+ y height)) (mth/round y))
|
:style style}])]))
|
||||||
:style style}]))]))
|
|
||||||
|
|
||||||
(mf/defc grid-display-frame [{:keys [frame zoom]}]
|
(mf/defc grid-display-frame
|
||||||
(let [grids (:grids frame)]
|
[{:keys [frame zoom]}]
|
||||||
(for [[index {:keys [type display] :as grid}] (map-indexed vector grids)]
|
(for [[index {:keys [type display] :as grid}] (->> (:grids frame)
|
||||||
(let [props #js {:key (str (:id frame) "-grid-" index)
|
(filter :display)
|
||||||
:frame frame
|
(map-indexed vector))]
|
||||||
:zoom zoom
|
(let [props #js {:key (str (:id frame) "-grid-" index)
|
||||||
:grid grid}]
|
:frame frame
|
||||||
(when display
|
:zoom zoom
|
||||||
(case type
|
:grid grid}]
|
||||||
:square [:> square-grid props]
|
(case type
|
||||||
:column [:> layout-grid props]
|
:square [:> square-grid props]
|
||||||
:row [:> layout-grid props]))))))
|
:column [:> layout-grid props]
|
||||||
|
:row [:> layout-grid props]))))
|
||||||
|
|
||||||
(def shapes-moving-ref
|
|
||||||
(let [moving-shapes (fn [local]
|
|
||||||
(when (= :move (:transform local))
|
|
||||||
(:selected local)))]
|
|
||||||
(l/derived moving-shapes refs/workspace-local)))
|
|
||||||
|
|
||||||
(mf/defc frame-grid
|
(mf/defc frame-grid
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [zoom]}]
|
[{:keys [zoom transform selected]}]
|
||||||
(let [frames (mf/deref refs/workspace-frames)
|
(let [frames (mf/deref refs/workspace-frames)
|
||||||
shapes-moving (mf/deref shapes-moving-ref)]
|
moving (when (= :move transform) selected)
|
||||||
|
is-moving? #(contains? moving (:id %))]
|
||||||
|
|
||||||
[:g.grid-display {:style {:pointer-events "none"}}
|
[:g.grid-display {:style {:pointer-events "none"}}
|
||||||
(for [frame (->> frames (remove #(contains? shapes-moving (:id %))))]
|
(for [frame (remove is-moving? frames)]
|
||||||
[:& grid-display-frame {:key (str "grid-" (:id frame))
|
[:& grid-display-frame {:key (str "grid-" (:id frame))
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:frame (gsh/transform-shape frame)}])]))
|
:frame (gsh/transform-shape frame)}])]))
|
||||||
|
|
|
@ -23,61 +23,65 @@
|
||||||
frame-length-no-margins (- frame-length (+ margin (- margin gutter)))]
|
frame-length-no-margins (- frame-length (+ margin (- margin gutter)))]
|
||||||
(mth/floor (/ frame-length-no-margins (+ item-length gutter)))))
|
(mth/floor (/ frame-length-no-margins (+ item-length gutter)))))
|
||||||
|
|
||||||
|
(defn- calculate-generic-grid
|
||||||
|
[v width {:keys [size gutter margin item-length type]}]
|
||||||
|
(let [size (if (number? size)
|
||||||
|
size
|
||||||
|
(calculate-size width item-length margin gutter))
|
||||||
|
parts (/ width size)
|
||||||
|
|
||||||
|
width' (min (or item-length ##Inf) (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size))))
|
||||||
|
|
||||||
|
offset (case type
|
||||||
|
:right (- width (* width' size) (* gutter (dec size)) margin)
|
||||||
|
:center (/ (- width (* width' size) (* gutter (dec size))) 2)
|
||||||
|
margin)
|
||||||
|
|
||||||
|
gutter (if (= :stretch type)
|
||||||
|
(let [gutter (/ (- width (* width' size) (* margin 2)) (dec size))]
|
||||||
|
(if (mth/finite? gutter) gutter 0))
|
||||||
|
gutter)
|
||||||
|
|
||||||
|
next-v (fn [cur-val]
|
||||||
|
(+ offset v (* (+ width' gutter) cur-val)))]
|
||||||
|
|
||||||
|
[size width' next-v]))
|
||||||
|
|
||||||
(defn- calculate-column-grid
|
(defn- calculate-column-grid
|
||||||
[{:keys [width height x y] :as frame} {:keys [size gutter margin item-length type] :as params}]
|
[{:keys [width height x y] :as frame} params]
|
||||||
(let [size (if (number? size) size (calculate-size width item-length margin gutter))
|
(let [[size width next-x] (calculate-generic-grid x width params)]
|
||||||
parts (/ width size)
|
[size width height next-x (constantly y)]))
|
||||||
item-width (min (or item-length ##Inf) (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size))))
|
|
||||||
item-height height
|
|
||||||
initial-offset (case type
|
|
||||||
:right (- width (* item-width size) (* gutter (dec size)) margin)
|
|
||||||
:center (/ (- width (* item-width size) (* gutter (dec size))) 2)
|
|
||||||
margin)
|
|
||||||
gutter (if (= :stretch type) (/ (- width (* item-width size) (* margin 2)) (dec size)) gutter)
|
|
||||||
next-x (fn [cur-val] (+ initial-offset x (* (+ item-width gutter) cur-val)))
|
|
||||||
next-y (fn [_] y)]
|
|
||||||
[size item-width item-height next-x next-y]))
|
|
||||||
|
|
||||||
(defn- calculate-row-grid
|
(defn- calculate-row-grid
|
||||||
[{:keys [width height x y] :as frame} {:keys [size gutter margin item-length type] :as params}]
|
[{:keys [width height x y] :as frame} params]
|
||||||
(let [size (if (number? size) size (calculate-size height item-length margin gutter))
|
(let [[size height next-y] (calculate-generic-grid y height params)]
|
||||||
parts (/ height size)
|
[size width height (constantly x) next-y]))
|
||||||
item-width width
|
|
||||||
item-height (min (or item-length ##Inf) (+ parts (- gutter) (/ gutter size) (- (/ (* margin 2) size))))
|
|
||||||
initial-offset (case type
|
|
||||||
:right (- height (* item-height size) (* gutter (dec size)) margin)
|
|
||||||
:center (/ (- height (* item-height size) (* gutter (dec size))) 2)
|
|
||||||
margin)
|
|
||||||
gutter (if (= :stretch type) (/ (- height (* item-height size) (* margin 2)) (dec size)) gutter)
|
|
||||||
next-x (fn [_] x)
|
|
||||||
next-y (fn [cur-val] (+ initial-offset y (* (+ item-height gutter) cur-val)))]
|
|
||||||
[size item-width item-height next-x next-y]))
|
|
||||||
|
|
||||||
(defn- calculate-square-grid
|
(defn- calculate-square-grid
|
||||||
[{:keys [width height x y] :as frame} {:keys [size] :as params}]
|
[{:keys [width height x y] :as frame} {:keys [size] :as params}]
|
||||||
(let [col-size (quot width size)
|
(let [col-size (quot width size)
|
||||||
row-size (quot height size)
|
row-size (quot height size)
|
||||||
as-row-col (fn [value] [(quot value col-size) (rem value col-size)])
|
as-row-col (fn [value] [(quot value col-size) (rem value col-size)])
|
||||||
next-x (fn [cur-val]
|
next-x (fn [cur-val]
|
||||||
(let [[_ col] (as-row-col cur-val)] (+ x (* col size))))
|
(let [[_ col] (as-row-col cur-val)] (+ x (* col size))))
|
||||||
next-y (fn [cur-val]
|
next-y (fn [cur-val]
|
||||||
(let [[row _] (as-row-col cur-val)] (+ y (* row size))))]
|
(let [[row _] (as-row-col cur-val)] (+ y (* row size))))]
|
||||||
|
|
||||||
[(* col-size row-size) size size next-x next-y]))
|
[(* col-size row-size) size size next-x next-y]))
|
||||||
|
|
||||||
(defn grid-areas
|
(defn grid-areas
|
||||||
"Given a frame and the grid parameters returns the areas defined on the grid"
|
"Given a frame and the grid parameters returns the areas defined on the grid"
|
||||||
[frame grid]
|
[frame grid]
|
||||||
(let [grid-fn (case (-> grid :type)
|
(let [grid-fn (case (-> grid :type)
|
||||||
:column calculate-column-grid
|
:column calculate-column-grid
|
||||||
:row calculate-row-grid
|
:row calculate-row-grid
|
||||||
:square calculate-square-grid)
|
:square calculate-square-grid)
|
||||||
[num-items item-width item-height next-x next-y] (grid-fn frame (-> grid :params))]
|
[num-items item-width item-height next-x next-y] (grid-fn frame (-> grid :params))]
|
||||||
(->>
|
(->> (range 0 num-items)
|
||||||
(range 0 num-items)
|
(map #(hash-map :x (next-x %)
|
||||||
(map #(hash-map :x (next-x %)
|
:y (next-y %)
|
||||||
:y (next-y %)
|
:width item-width
|
||||||
:width item-width
|
:height item-height)))))
|
||||||
:height item-height)))))
|
|
||||||
|
|
||||||
(defn grid-area-points
|
(defn grid-area-points
|
||||||
[{:keys [x y width height]}]
|
[{:keys [x y width height]}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue