mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 08:46:11 +02:00
commit
fa02df7106
5 changed files with 111 additions and 48 deletions
|
@ -28,8 +28,6 @@
|
||||||
h-center? (ctl/h-center? parent)
|
h-center? (ctl/h-center? parent)
|
||||||
h-end? (ctl/h-end? parent)
|
h-end? (ctl/h-end? parent)
|
||||||
|
|
||||||
around? (ctl/space-around? parent)
|
|
||||||
between? (ctl/space-between? parent)
|
|
||||||
fill-w? (ctl/fill-width? child)
|
fill-w? (ctl/fill-width? child)
|
||||||
fill-h? (ctl/fill-height? child)
|
fill-h? (ctl/fill-height? child)
|
||||||
|
|
||||||
|
@ -70,7 +68,7 @@
|
||||||
(gpt/add base-p (hv 0.01))
|
(gpt/add base-p (hv 0.01))
|
||||||
(gpt/add base-p (vv 0.01))]
|
(gpt/add base-p (vv 0.01))]
|
||||||
|
|
||||||
(or col? h-start? around? between?)
|
(and col? h-start?)
|
||||||
(conj (gpt/add base-p (hv min-width)))
|
(conj (gpt/add base-p (hv min-width)))
|
||||||
|
|
||||||
(and col? h-center?)
|
(and col? h-center?)
|
||||||
|
@ -79,7 +77,7 @@
|
||||||
(and col? h-center?)
|
(and col? h-center?)
|
||||||
(conj (gpt/subtract base-p (hv min-width)))
|
(conj (gpt/subtract base-p (hv min-width)))
|
||||||
|
|
||||||
(or row? v-start? around? between?)
|
(and row? v-start?)
|
||||||
(conj (gpt/add base-p (vv min-height)))
|
(conj (gpt/add base-p (vv min-height)))
|
||||||
|
|
||||||
(and row? v-center?)
|
(and row? v-center?)
|
||||||
|
|
|
@ -134,25 +134,41 @@
|
||||||
(defn wrap? [{:keys [layout-wrap-type]}]
|
(defn wrap? [{:keys [layout-wrap-type]}]
|
||||||
(= layout-wrap-type :wrap))
|
(= layout-wrap-type :wrap))
|
||||||
|
|
||||||
(defn fill-width? [child]
|
(defn fill-width?
|
||||||
(= :fill (:layout-item-h-sizing child)))
|
([objects id]
|
||||||
|
(= :fill (dm/get-in objects [id :layout-item-h-sizing])))
|
||||||
|
([child]
|
||||||
|
(= :fill (:layout-item-h-sizing child))))
|
||||||
|
|
||||||
(defn fill-height? [child]
|
(defn fill-height?
|
||||||
(= :fill (:layout-item-v-sizing child)))
|
([objects id]
|
||||||
|
(= :fill (dm/get-in objects [id :layout-item-v-sizing])))
|
||||||
|
([child]
|
||||||
|
(= :fill (:layout-item-v-sizing child))))
|
||||||
|
|
||||||
(defn auto-width? [child]
|
(defn auto-width?
|
||||||
(= :auto (:layout-item-h-sizing child)))
|
([objects id]
|
||||||
|
(= :auto (dm/get-in objects [id :layout-item-h-sizing])))
|
||||||
|
([child]
|
||||||
|
(= :auto (:layout-item-h-sizing child))))
|
||||||
|
|
||||||
(defn auto-height? [child]
|
(defn auto-height?
|
||||||
(= :auto (:layout-item-v-sizing child)))
|
([objects id]
|
||||||
|
(= :auto (dm/get-in objects [id :layout-item-v-sizing])))
|
||||||
|
([child]
|
||||||
|
(= :auto (:layout-item-v-sizing child))))
|
||||||
|
|
||||||
(defn col?
|
(defn col?
|
||||||
[{:keys [layout-flex-dir]}]
|
([objects id]
|
||||||
(or (= :column layout-flex-dir) (= :column-reverse layout-flex-dir)))
|
(col? (get objects id)))
|
||||||
|
([{:keys [layout-flex-dir]}]
|
||||||
|
(or (= :column layout-flex-dir) (= :column-reverse layout-flex-dir))))
|
||||||
|
|
||||||
(defn row?
|
(defn row?
|
||||||
[{:keys [layout-flex-dir]}]
|
([objects id]
|
||||||
(or (= :row layout-flex-dir) (= :row-reverse layout-flex-dir)))
|
(row? (get objects id)))
|
||||||
|
([{:keys [layout-flex-dir]}]
|
||||||
|
(or (= :row layout-flex-dir) (= :row-reverse layout-flex-dir))))
|
||||||
|
|
||||||
(defn gaps
|
(defn gaps
|
||||||
[{:keys [layout-gap]}]
|
[{:keys [layout-gap]}]
|
||||||
|
@ -315,3 +331,22 @@
|
||||||
|
|
||||||
(defn align-self-stretch? [{:keys [layout-item-align-self]}]
|
(defn align-self-stretch? [{:keys [layout-item-align-self]}]
|
||||||
(= :stretch layout-item-align-self))
|
(= :stretch layout-item-align-self))
|
||||||
|
|
||||||
|
(defn change-h-sizing?
|
||||||
|
[frame-id objects children-ids]
|
||||||
|
(and (layout? objects frame-id)
|
||||||
|
(auto-width? objects frame-id)
|
||||||
|
(or (and (col? objects frame-id)
|
||||||
|
(every? (partial fill-width? objects) children-ids))
|
||||||
|
(and (row? objects frame-id)
|
||||||
|
(some (partial fill-width? objects) children-ids)))))
|
||||||
|
|
||||||
|
(defn change-v-sizing?
|
||||||
|
[frame-id objects children-ids]
|
||||||
|
(and (layout? objects frame-id)
|
||||||
|
(auto-height? objects frame-id)
|
||||||
|
(or (and (col? objects frame-id)
|
||||||
|
(some (partial fill-height? objects) children-ids))
|
||||||
|
(and (row? objects frame-id)
|
||||||
|
(every? (partial fill-height? objects) children-ids)))))
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ volumes:
|
||||||
postgres_data_pg15:
|
postgres_data_pg15:
|
||||||
user_data:
|
user_data:
|
||||||
minio_data:
|
minio_data:
|
||||||
|
redis_data:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
main:
|
main:
|
||||||
|
@ -100,6 +101,8 @@ services:
|
||||||
hostname: "penpot-devenv-redis"
|
hostname: "penpot-devenv-redis"
|
||||||
container_name: "penpot-devenv-redis"
|
container_name: "penpot-devenv-redis"
|
||||||
restart: always
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- "redis_data:/data"
|
||||||
|
|
||||||
mailer:
|
mailer:
|
||||||
image: sj26/mailcatcher:latest
|
image: sj26/mailcatcher:latest
|
||||||
|
|
|
@ -651,20 +651,20 @@
|
||||||
(-> (pcb/empty-changes it page-id)
|
(-> (pcb/empty-changes it page-id)
|
||||||
(pcb/with-objects objects)
|
(pcb/with-objects objects)
|
||||||
|
|
||||||
; Move the shapes
|
;; Move the shapes
|
||||||
(pcb/change-parent parent-id
|
(pcb/change-parent parent-id
|
||||||
shapes
|
shapes
|
||||||
to-index)
|
to-index)
|
||||||
|
|
||||||
; Remove empty groups
|
;; Remove empty groups
|
||||||
(pcb/remove-objects groups-to-delete)
|
(pcb/remove-objects groups-to-delete)
|
||||||
|
|
||||||
; Unmask groups whose mask have moved outside
|
;; Unmask groups whose mask have moved outside
|
||||||
(pcb/update-shapes groups-to-unmask
|
(pcb/update-shapes groups-to-unmask
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(assoc shape :masked-group? false)))
|
(assoc shape :masked-group? false)))
|
||||||
|
|
||||||
; Detach shapes moved out of their component
|
;; Detach shapes moved out of their component
|
||||||
(pcb/update-shapes shapes-to-detach
|
(pcb/update-shapes shapes-to-detach
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(assoc shape :component-id nil
|
(assoc shape :component-id nil
|
||||||
|
@ -674,17 +674,17 @@
|
||||||
:shape-ref nil
|
:shape-ref nil
|
||||||
:touched nil)))
|
:touched nil)))
|
||||||
|
|
||||||
; Make non root a component moved inside another one
|
;; Make non root a component moved inside another one
|
||||||
(pcb/update-shapes shapes-to-deroot
|
(pcb/update-shapes shapes-to-deroot
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(assoc shape :component-root? nil)))
|
(assoc shape :component-root? nil)))
|
||||||
|
|
||||||
; Make root a subcomponent moved outside its parent component
|
;; Make root a subcomponent moved outside its parent component
|
||||||
(pcb/update-shapes shapes-to-reroot
|
(pcb/update-shapes shapes-to-reroot
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(assoc shape :component-root? true)))
|
(assoc shape :component-root? true)))
|
||||||
|
|
||||||
; Reset constraints depending on the new parent
|
;; Reset constraints depending on the new parent
|
||||||
(pcb/update-shapes shapes-to-unconstraint
|
(pcb/update-shapes shapes-to-unconstraint
|
||||||
(fn [shape]
|
(fn [shape]
|
||||||
(let [parent (get objects parent-id)
|
(let [parent (get objects parent-id)
|
||||||
|
@ -699,7 +699,19 @@
|
||||||
:constraints-v (gsh/default-constraints-v moved-shape))))
|
:constraints-v (gsh/default-constraints-v moved-shape))))
|
||||||
{:ignore-touched true})
|
{:ignore-touched true})
|
||||||
|
|
||||||
; Resize parent containers that need to
|
;; Fix the sizing when moving a shape
|
||||||
|
(pcb/update-shapes parents
|
||||||
|
(fn [parent]
|
||||||
|
(if (ctl/layout? parent)
|
||||||
|
(cond-> parent
|
||||||
|
(ctl/change-h-sizing? (:id parent) objects (:shapes parent))
|
||||||
|
(assoc :layout-item-h-sizing :fix)
|
||||||
|
|
||||||
|
(ctl/change-v-sizing? (:id parent) objects (:shapes parent))
|
||||||
|
(assoc :layout-item-v-sizing :fix))
|
||||||
|
parent)))
|
||||||
|
|
||||||
|
;; Resize parent containers that need to
|
||||||
(pcb/resize-parents parents))))
|
(pcb/resize-parents parents))))
|
||||||
|
|
||||||
(defn relocate-shapes
|
(defn relocate-shapes
|
||||||
|
@ -719,9 +731,9 @@
|
||||||
|
|
||||||
;; If we try to move a parent into a child we remove it
|
;; If we try to move a parent into a child we remove it
|
||||||
ids (filter #(not (cph/is-parent? objects parent-id %)) ids)
|
ids (filter #(not (cph/is-parent? objects parent-id %)) ids)
|
||||||
parents (if ignore-parents?
|
|
||||||
#{parent-id}
|
all-parents (into #{parent-id} (map #(cph/get-parent-id objects %)) ids)
|
||||||
(into #{parent-id} (map #(cph/get-parent-id objects %)) ids))
|
parents (if ignore-parents? #{parent-id} all-parents)
|
||||||
|
|
||||||
groups-to-delete
|
groups-to-delete
|
||||||
(loop [current-id (first parents)
|
(loop [current-id (first parents)
|
||||||
|
@ -814,17 +826,12 @@
|
||||||
shapes-to-reroot
|
shapes-to-reroot
|
||||||
shapes-to-deroot
|
shapes-to-deroot
|
||||||
ids)
|
ids)
|
||||||
|
|
||||||
layouts-to-update
|
|
||||||
(into #{}
|
|
||||||
(filter (partial ctl/layout? objects))
|
|
||||||
(concat [parent-id] (cph/get-parent-ids objects parent-id)))
|
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
|
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes)
|
||||||
(dwco/expand-collapse parent-id)
|
(dwco/expand-collapse parent-id)
|
||||||
(ptk/data-event :layout/update layouts-to-update)
|
(ptk/data-event :layout/update (concat all-parents ids))
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
|
|
||||||
(defn relocate-selected-shapes
|
(defn relocate-selected-shapes
|
||||||
|
|
|
@ -174,42 +174,62 @@
|
||||||
modif-tree)))
|
modif-tree)))
|
||||||
|
|
||||||
(defn build-change-frame-modifiers
|
(defn build-change-frame-modifiers
|
||||||
[modif-tree objects selected target-frame drop-index]
|
[modif-tree objects selected target-frame-id drop-index]
|
||||||
|
|
||||||
(let [origin-frame-ids (->> selected (group-by #(get-in objects [% :frame-id])))
|
(let [origin-frame-ids (->> selected (group-by #(get-in objects [% :frame-id])))
|
||||||
child-set (set (get-in objects [target-frame :shapes]))
|
child-set (set (get-in objects [target-frame-id :shapes]))
|
||||||
layout? (ctl/layout? objects target-frame)
|
|
||||||
|
target-frame (get objects target-frame-id)
|
||||||
|
target-layout? (ctl/layout? target-frame)
|
||||||
|
|
||||||
|
children-ids (concat (:shapes target-frame) selected)
|
||||||
|
|
||||||
set-parent-ids
|
set-parent-ids
|
||||||
(fn [modif-tree shapes target-frame]
|
(fn [modif-tree shapes target-frame-id]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [modif-tree id]
|
(fn [modif-tree id]
|
||||||
(update-in
|
(update-in
|
||||||
modif-tree
|
modif-tree
|
||||||
[id :modifiers]
|
[id :modifiers]
|
||||||
#(-> %
|
#(-> %
|
||||||
(ctm/change-property :frame-id target-frame)
|
(ctm/change-property :frame-id target-frame-id)
|
||||||
(ctm/change-property :parent-id target-frame))))
|
(ctm/change-property :parent-id target-frame-id))))
|
||||||
modif-tree
|
modif-tree
|
||||||
shapes))
|
shapes))
|
||||||
|
|
||||||
update-frame-modifiers
|
update-frame-modifiers
|
||||||
(fn [modif-tree [original-frame shapes]]
|
(fn [modif-tree [original-frame shapes]]
|
||||||
(let [shapes (->> shapes (d/removev #(= target-frame %)))
|
(let [shapes (->> shapes (d/removev #(= target-frame-id %)))
|
||||||
shapes (cond->> shapes
|
shapes (cond->> shapes
|
||||||
(and layout? (= original-frame target-frame))
|
(and target-layout? (= original-frame target-frame-id))
|
||||||
;; When movining inside a layout frame remove the shapes that are not immediate children
|
;; When movining inside a layout frame remove the shapes that are not immediate children
|
||||||
(filterv #(contains? child-set %)))]
|
(filterv #(contains? child-set %)))
|
||||||
|
children-ids (->> (dm/get-in objects [original-frame :shapes])
|
||||||
|
(remove (set selected)))
|
||||||
|
|
||||||
|
h-sizing? (ctl/change-h-sizing? original-frame objects children-ids)
|
||||||
|
v-sizing? (ctl/change-v-sizing? original-frame objects children-ids)]
|
||||||
(cond-> modif-tree
|
(cond-> modif-tree
|
||||||
(not= original-frame target-frame)
|
(not= original-frame target-frame-id)
|
||||||
(-> (modifier-remove-from-parent objects shapes)
|
(-> (modifier-remove-from-parent objects shapes)
|
||||||
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index)
|
(update-in [target-frame-id :modifiers] ctm/add-children shapes drop-index)
|
||||||
(set-parent-ids shapes target-frame))
|
(set-parent-ids shapes target-frame-id)
|
||||||
|
(cond-> h-sizing?
|
||||||
|
(update-in [original-frame :modifiers] ctm/change-property :layout-item-h-sizing :fix))
|
||||||
|
(cond-> v-sizing?
|
||||||
|
(update-in [original-frame :modifiers] ctm/change-property :layout-item-v-sizing :fix)))
|
||||||
|
|
||||||
(and layout? (= original-frame target-frame))
|
(and target-layout? (= original-frame target-frame-id))
|
||||||
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index))))]
|
(update-in [target-frame-id :modifiers] ctm/add-children shapes drop-index))))]
|
||||||
|
|
||||||
(reduce update-frame-modifiers modif-tree origin-frame-ids)))
|
(as-> modif-tree $
|
||||||
|
(reduce update-frame-modifiers $ origin-frame-ids)
|
||||||
|
(cond-> $
|
||||||
|
(ctl/change-h-sizing? target-frame-id objects children-ids)
|
||||||
|
(update-in [target-frame-id :modifiers] ctm/change-property :layout-item-h-sizing :fix))
|
||||||
|
(cond-> $
|
||||||
|
(ctl/change-v-sizing? target-frame-id objects children-ids)
|
||||||
|
(update-in [target-frame-id :modifiers] ctm/change-property :layout-item-v-sizing :fix)))))
|
||||||
|
|
||||||
(defn modif->js
|
(defn modif->js
|
||||||
[modif-tree objects]
|
[modif-tree objects]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue