mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 18:48:37 -05:00
✨ Expand containing layer when selecting a shape
This commit is contained in:
parent
7917370136
commit
adde1d3d63
3 changed files with 62 additions and 34 deletions
|
@ -74,6 +74,7 @@
|
||||||
{:zoom 1
|
{:zoom 1
|
||||||
:flags #{}
|
:flags #{}
|
||||||
:selected #{}
|
:selected #{}
|
||||||
|
:expanded {}
|
||||||
:drawing nil
|
:drawing nil
|
||||||
:drawing-tool nil
|
:drawing-tool nil
|
||||||
:tooltip nil
|
:tooltip nil
|
||||||
|
@ -445,17 +446,28 @@
|
||||||
|
|
||||||
;; --- Toggle shape's selection status (selected or deselected)
|
;; --- Toggle shape's selection status (selected or deselected)
|
||||||
|
|
||||||
|
(declare expand-all-parents)
|
||||||
|
|
||||||
(defn select-shape
|
(defn select-shape
|
||||||
[id]
|
([id] (select-shape id false))
|
||||||
(us/verify ::us/uuid id)
|
([id toggle?]
|
||||||
(ptk/reify ::select-shape
|
(us/verify ::us/uuid id)
|
||||||
ptk/UpdateEvent
|
(ptk/reify ::select-shape
|
||||||
(update [_ state]
|
ptk/UpdateEvent
|
||||||
(update-in state [:workspace-local :selected]
|
(update [_ state]
|
||||||
(fn [selected]
|
(update-in state [:workspace-local :selected]
|
||||||
(if (contains? selected id)
|
(fn [selected]
|
||||||
(disj selected id)
|
(if-not toggle?
|
||||||
(conj selected id)))))))
|
(conj selected id)
|
||||||
|
(if (contains? selected id)
|
||||||
|
(disj selected id)
|
||||||
|
(conj selected id))))))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [page-id (get-in state [:workspace-page :id])
|
||||||
|
objects (get-in state [:workspace-data page-id :objects])]
|
||||||
|
(rx/of (expand-all-parents [id] objects)))))))
|
||||||
|
|
||||||
(defn select-shapes
|
(defn select-shapes
|
||||||
[ids]
|
[ids]
|
||||||
|
@ -463,7 +475,13 @@
|
||||||
(ptk/reify ::select-shapes
|
(ptk/reify ::select-shapes
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(assoc-in state [:workspace-local :selected] ids))))
|
(assoc-in state [:workspace-local :selected] ids))
|
||||||
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [page-id (get-in state [:workspace-page :id])
|
||||||
|
objects (get-in state [:workspace-data page-id :objects])]
|
||||||
|
(rx/of (expand-all-parents ids objects))))))
|
||||||
|
|
||||||
(def deselect-all
|
(def deselect-all
|
||||||
"Clear all possible state of drawing, edition
|
"Clear all possible state of drawing, edition
|
||||||
|
@ -686,15 +704,15 @@
|
||||||
(defn select-inside-group
|
(defn select-inside-group
|
||||||
[group-id position]
|
[group-id position]
|
||||||
(ptk/reify ::select-inside-group
|
(ptk/reify ::select-inside-group
|
||||||
ptk/UpdateEvent
|
ptk/WatchEvent
|
||||||
(update [_ state]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
group (get objects group-id)
|
group (get objects group-id)
|
||||||
children (map #(get objects %) (:shapes group))
|
children (map #(get objects %) (:shapes group))
|
||||||
selected (->> children (filter #(geom/has-point? % position)) first)]
|
selected (->> children (filter #(geom/has-point? % position)) first)]
|
||||||
(cond-> state
|
(when selected
|
||||||
selected (assoc-in [:workspace-local :selected] #{(:id selected)}))))))
|
(rx/of deselect-all (select-shape (:id selected))))))))
|
||||||
|
|
||||||
;; --- Update Shape Attrs
|
;; --- Update Shape Attrs
|
||||||
|
|
||||||
|
@ -1126,6 +1144,21 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update state :workspace-local dissoc :expanded))))
|
(update state :workspace-local dissoc :expanded))))
|
||||||
|
|
||||||
|
(defn expand-all-parents
|
||||||
|
[ids objects]
|
||||||
|
(ptk/reify ::expand-all-parents
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(let [expand-fn (fn [expanded]
|
||||||
|
(merge expanded
|
||||||
|
(->> ids
|
||||||
|
(map #(cp/get-all-parents % objects))
|
||||||
|
flatten
|
||||||
|
(filter #(not= % uuid/zero))
|
||||||
|
(map (fn [id] {id true}))
|
||||||
|
(into {}))))]
|
||||||
|
(update-in state [:workspace-local :expanded] expand-fn)))))
|
||||||
|
|
||||||
(defn recursive-assign
|
(defn recursive-assign
|
||||||
"A helper for assign recursively a shape attr."
|
"A helper for assign recursively a shape attr."
|
||||||
[id attr value]
|
[id attr value]
|
||||||
|
@ -1202,22 +1235,14 @@
|
||||||
(ptk/reify ::show-context-menu
|
(ptk/reify ::show-context-menu
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [selected (get-in state [:workspace-local :selected])
|
(let [mdata {:position position
|
||||||
selected (cond
|
|
||||||
(empty? selected)
|
|
||||||
(conj selected (:id shape))
|
|
||||||
|
|
||||||
(contains? selected (:id shape))
|
|
||||||
selected
|
|
||||||
|
|
||||||
:else
|
|
||||||
#{(:id shape)})
|
|
||||||
mdata {:position position
|
|
||||||
:selected selected
|
|
||||||
:shape shape}]
|
:shape shape}]
|
||||||
(-> state
|
(-> state
|
||||||
(assoc-in [:workspace-local :context-menu] mdata)
|
(assoc-in [:workspace-local :context-menu] mdata))))
|
||||||
(assoc-in [:workspace-local :selected] selected))))))
|
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(rx/of (select-shape (:id shape))))))
|
||||||
|
|
||||||
(def hide-context-menu
|
(def hide-context-menu
|
||||||
(ptk/reify ::hide-context-menu
|
(ptk/reify ::hide-context-menu
|
||||||
|
|
|
@ -41,10 +41,13 @@
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(when-not selected?
|
(if selected?
|
||||||
(when-not (or (empty? selected) (kbd/shift? event))
|
(when (kbd/shift? event)
|
||||||
(st/emit! dw/deselect-all))
|
(st/emit! (dw/select-shape id true)))
|
||||||
(st/emit! (dw/select-shape id)))
|
(do
|
||||||
|
(when-not (or (empty? selected) (kbd/shift? event))
|
||||||
|
(st/emit! dw/deselect-all))
|
||||||
|
(st/emit! (dw/select-shape id))))
|
||||||
(st/emit! (dw/start-move-selected)))))))
|
(st/emit! (dw/start-move-selected)))))))
|
||||||
|
|
||||||
(defn on-context-menu
|
(defn on-context-menu
|
||||||
|
|
|
@ -125,7 +125,7 @@
|
||||||
nil
|
nil
|
||||||
|
|
||||||
(.-ctrlKey event)
|
(.-ctrlKey event)
|
||||||
(st/emit! (dw/select-shape id))
|
(st/emit! (dw/select-shape id true))
|
||||||
|
|
||||||
(> (count selected) 1)
|
(> (count selected) 1)
|
||||||
(st/emit! dw/deselect-all
|
(st/emit! dw/deselect-all
|
||||||
|
|
Loading…
Add table
Reference in a new issue