0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

🐛 Fix issues with non updated selected

This commit is contained in:
alonso.torres 2021-05-05 14:22:59 +02:00 committed by Andrey Antukh
parent be0d1c19fa
commit a91a57581f
16 changed files with 91 additions and 99 deletions

View file

@ -573,7 +573,7 @@
(ptk/reify ::zoom-to-selected-shape
ptk/UpdateEvent
(update [_ state]
(let [selected (get-in state [:workspace-local :selected])]
(let [selected (wsh/lookup-selected state)]
(if (empty? selected)
state
(let [page-id (:current-page-id state)
@ -623,7 +623,7 @@
(ptk/reify ::update-selected-shapes
ptk/WatchEvent
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])]
(let [selected (wsh/lookup-selected state)]
(rx/from (map #(update-shape % attrs) selected))))))
;; --- Shape Movement (using keyboard shorcuts)
@ -661,7 +661,7 @@
(ptk/reify ::delete-selected
ptk/WatchEvent
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])]
(let [selected (wsh/lookup-selected state)]
(rx/of (dwc/delete-shapes selected)
(dws/deselect-all))))))
@ -677,7 +677,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
rchanges (mapv (fn [id]
(let [obj (get objects id)
parent (get objects (:parent-id obj))
@ -988,7 +988,7 @@
(ptk/reify ::relocate-selected-shapes
ptk/WatchEvent
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])]
(let [selected (wsh/lookup-selected state)]
(rx/of (relocate-shapes selected parent-id to-index))))))
@ -997,7 +997,7 @@
(ptk/reify ::start-editing-selected
ptk/WatchEvent
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])]
(let [selected (wsh/lookup-selected state)]
(if-not (= 1 (count selected))
(rx/empty)
@ -1048,7 +1048,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
moved (if (= 1 (count selected))
(align-object-to-frame objects (first selected) axis)
(align-objects-list objects selected axis))
@ -1079,7 +1079,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
moved (-> (map #(get objects %) selected)
(gal/distribute-space axis objects))
@ -1232,7 +1232,7 @@
(let [mdata (cond-> params
(some? shape)
(assoc :selected
(get-in state [:workspace-local :selected])))]
(wsh/lookup-selected state)))]
(assoc-in state [:workspace-local :context-menu] mdata)))))
(defn show-shape-context-menu
@ -1242,7 +1242,7 @@
(ptk/reify ::show-shape-context-menu
ptk/WatchEvent
(watch [_ state stream]
(let [selected (get-in state [:workspace-local :selected])]
(let [selected (wsh/lookup-selected state)]
(rx/concat
(when-not (selected (:id shape))
(rx/of (dws/select-shape (:id shape))))
@ -1313,7 +1313,7 @@
ptk/WatchEvent
(watch [_ state stream]
(let [objects (wsh/lookup-page-objects state)
selected (->> (get-in state [:workspace-local :selected])
selected (->> (wsh/lookup-selected state)
(cp/clean-loops objects))
pdata (reduce (partial collect-object-ids objects) {} selected)
initial {:type :copied-shapes
@ -1412,9 +1412,8 @@
(js/console.error "Clipboard error:" err))))))
(defn selected-frame? [state]
(let [selected (get-in state [:workspace-local :selected])
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)]
(let [selected (wsh/lookup-selected state)
objects (wsh/lookup-page-objects state)]
(and (and (= 1 (count selected))
(= :frame (get-in objects [(first selected) :type]))))))
@ -1454,7 +1453,7 @@
(let [page-objects (wsh/lookup-page-objects state)
selected-objs (map #(get objects %) selected)
has-frame? (d/seek #(= (:type %) :frame) selected-objs)
page-selected (get-in state [:workspace-local :selected])
page-selected (wsh/lookup-selected state)
wrapper (gsh/selection-rect selected-objs)
orig-pos (gpt/point (:x1 wrapper) (:y1 wrapper))]
(cond
@ -1635,7 +1634,7 @@
ptk/WatchEvent
(watch [_ state stream]
(let [initial-pos @ms/mouse-position
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
stopper (rx/filter ms/mouse-up? stream)]
(when (= 1 (count selected))
(rx/concat
@ -1651,7 +1650,7 @@
(update [_ state]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected-shape-id (-> state (get-in [:workspace-local :selected]) first)
selected-shape-id (-> state wsh/lookup-selected first)
selected-shape (get objects selected-shape-id)
selected-shape-frame-id (:frame-id selected-shape)
start-frame (get objects selected-shape-frame-id)
@ -1676,7 +1675,7 @@
objects (wsh/lookup-page-objects state page-id)
frame (dwc/get-frame-at-point objects position)
shape-id (first (get-in state [:workspace-local :selected]))
shape-id (-> state wsh/lookup-selected first)
shape (get objects shape-id)]
(when-not (= position initial-pos)

View file

@ -191,7 +191,7 @@
(ptk/reify ::picker-for-selected-shape
ptk/WatchEvent
(watch [_ state stream]
(let [ids (get-in state [:workspace-local :selected])
(let [ids (wsh/lookup-selected state)
stop? (rx/filter (ptk/type? ::stop-picker) stream)
update-events
@ -227,7 +227,7 @@
(ptk/reify ::start-gradient
ptk/UpdateEvent
(update [_ state]
(let [id (first (get-in state [:workspace-local :selected]))]
(let [id (-> state wsh/lookup-selected first)]
(-> state
(assoc-in [:workspace-local :current-gradient] gradient)
(assoc-in [:workspace-local :current-gradient :shape-id] id))))))

View file

@ -291,7 +291,7 @@
(retrieve-used-names)
(generate-unique-name (:name attrs)))
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
[rchanges uchanges] (add-shape-changes
page-id

View file

@ -103,7 +103,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
selected (cp/clean-loops objects selected)
shapes (shapes-for-grouping objects selected)]
(when-not (empty? shapes)
@ -117,7 +117,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
group-id (first selected)
group (get objects group-id)]
(when (and (= 1 (count selected))
@ -132,7 +132,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
selected (cp/clean-loops objects selected)
shapes (shapes-for-grouping objects selected)]
(when-not (empty? shapes)
@ -187,7 +187,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])]
selected (wsh/lookup-selected state)]
(when (= (count selected) 1)
(let [group (get objects (first selected))

View file

@ -239,7 +239,7 @@
(let [file-id (:current-file-id state)
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
selected (cp/clean-loops objects selected)]
(let [[group rchanges uchanges]
(dwlh/generate-add-component selected objects page-id file-id)]

View file

@ -121,7 +121,7 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selection (-> state
(get-in [:workspace-local :selected] #{})
wsh/lookup-selected
(conj id))]
(-> state
(assoc-in [:workspace-local :selected]
@ -148,7 +148,7 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
new-selected (let [selected-objs
(->> (get-in state [:workspace-local :selected])
(->> (wsh/lookup-selected state)
(map #(get objects %)))
frame-ids
@ -207,7 +207,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
initial-set (if preserve?
selected
lks/empty-linked-set)
@ -381,8 +381,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
delta (gpt/point 0 0)
unames (dwc/retrieve-used-names objects)

View file

@ -6,20 +6,7 @@
(ns app.main.data.workspace.state-helpers
(:require
#_[app.common.data :as d]
#_[app.common.geom.proportions :as gpr]
#_[app.common.geom.shapes :as gsh]
#_[app.common.pages :as cp]
#_[app.common.spec :as us]
#_[app.common.uuid :as uuid]
#_[app.main.data.workspace.changes :as dch]
#_[app.main.data.workspace.undo :as dwu]
#_[app.main.streams :as ms]
#_[app.main.worker :as uw]
#_[app.util.logging :as log]
#_[beicon.core :as rx]
#_[cljs.spec.alpha :as s]
#_[potok.core :as ptk]))
[app.common.data :as d]))
(defn lookup-page-objects
([state]
@ -37,3 +24,11 @@
([state component-id]
(get-in state [:workspace-data :components component-id :objects])))
(defn lookup-selected
[state]
(let [selected (get-in state [:workspace-local :selected])
objects (lookup-page-objects state)
is-present? (fn [id] (contains? objects id))]
(into (d/ordered-set)
(filter is-present?)
selected)))

View file

@ -419,7 +419,7 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
frame-id (cp/frame-id-by-position objects position)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
x (- x vb-x (/ vb-width 2))

View file

@ -207,7 +207,7 @@
ptk/UpdateEvent
(update [_ state]
(let [objects (wsh/lookup-page-objects state)
selected (->> state :workspace-local :selected (map #(get objects %)))]
selected (->> state wsh/lookup-selected (mapv #(get objects %)))]
(cond-> state
(and (= 1 (count selected))
(= (-> selected first :type) :text))

View file

@ -210,7 +210,7 @@
ptk/WatchEvent
(watch [_ state stream]
(let [initial (deref ms/mouse-position)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
stopper (rx/filter ms/mouse-up? stream)]
(->> ms/mouse-position
(rx/take-until stopper)
@ -284,7 +284,7 @@
(watch [_ state stream]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
ids (if (nil? ids) (get-in state [:workspace-local :selected]) ids)
ids (if (nil? ids) (wsh/lookup-selected state) ids)
shapes (mapv #(get objects %) ids)
stopper (rx/filter ms/mouse-up? stream)
layout (get state :workspace-layout)
@ -361,7 +361,7 @@
ptk/WatchEvent
(watch [_ state stream]
(if (= same-event (get-in state [:workspace-local :current-move-selected]))
(let [selected (get-in state [:workspace-local :selected])
(let [selected (wsh/lookup-selected state)
move-events (->> stream
(rx/filter (ptk/type? ::move-selected))
(rx/filter #(= direction (deref %))))
@ -519,7 +519,7 @@
ptk/WatchEvent
(watch [_ state stream]
(let [objects (wsh/lookup-page-objects state)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
shapes (map #(get objects %) selected)
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
origin (gpt/point (:x selrect) (+ (:y selrect) (/ (:height selrect) 2)))]
@ -536,7 +536,7 @@
ptk/WatchEvent
(watch [_ state stream]
(let [objects (wsh/lookup-page-objects state)
selected (get-in state [:workspace-local :selected])
selected (wsh/lookup-selected state)
shapes (map #(get objects %) selected)
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
origin (gpt/point (+ (:x selrect) (/ (:width selrect) 2)) (:y selrect))]

View file

@ -7,13 +7,14 @@
(ns app.main.refs
"A collection of derived refs."
(:require
[beicon.core :as rx]
[okulary.core :as l]
[app.common.data :as d]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
[app.main.constants :as c]
[app.main.store :as st]))
[app.main.data.workspace.state-helpers :as wsh]
[app.main.store :as st]
[beicon.core :as rx]
[okulary.core :as l]))
;; ---- Global refs
@ -71,7 +72,7 @@
(l/derived :workspace-drawing st/state))
(def selected-shapes
(l/derived :selected workspace-local))
(l/derived wsh/lookup-selected st/state))
(defn make-selected-ref
[id]
@ -85,7 +86,6 @@
:edition
:edit-path
:tooltip
:selected
:panning
:picking-color?
:transform
@ -211,30 +211,28 @@
workspace-page-objects =))
(def selected-data
(l/derived #(let [selected (get-in % [:workspace-local :selected])
page-id (:current-page-id %)
objects (get-in % [:workspace-data :pages-index page-id :objects])]
(l/derived #(let [selected (wsh/lookup-selected %)
objects (wsh/lookup-page-objects %)]
(hash-map :selected selected
:page-id page-id
:objects objects))
st/state =))
(defn is-child-selected?
[id]
(letfn [(selector [{:keys [selected page-id objects]}]
(letfn [(selector [{:keys [selected objects]}]
(let [children (cp/get-children id objects)]
(some #(contains? selected %) children)))]
(l/derived selector selected-data =)))
(def selected-objects
(letfn [(selector [{:keys [selected page-id objects]}]
(letfn [(selector [{:keys [selected objects]}]
(->> selected
(map #(get objects %))
(filterv (comp not nil?))))]
(l/derived selector selected-data =)))
(def selected-shapes-with-children
(letfn [(selector [{:keys [selected page-id objects]}]
(letfn [(selector [{:keys [selected objects]}]
(let [children (->> selected
(mapcat #(cp/get-children % objects))
(filterv (comp not nil?)))]
@ -242,7 +240,7 @@
(l/derived selector selected-data =)))
(def selected-objects-with-children
(letfn [(selector [{:keys [selected page-id objects]}]
(letfn [(selector [{:keys [selected objects]}]
(let [children (->> selected
(mapcat #(cp/get-children % objects))
(filterv (comp not nil?)))

View file

@ -60,8 +60,10 @@
(mf/defc workspace-content
{::mf/wrap-props false}
[props]
(let [local (mf/deref refs/viewport-data)
{:keys [zoom vbox vport options-mode selected]} local
(let [selected (mf/deref refs/selected-shapes)
local (mf/deref refs/viewport-data)
{:keys [zoom vbox vport options-mode]} local
file (obj/get props "file")
layout (obj/get props "layout")]
[:*
@ -80,6 +82,7 @@
[:& viewport {:file file
:local local
:selected selected
:layout layout}]]]
[:& left-toolbar {:layout layout}]

View file

@ -7,8 +7,9 @@
(ns app.main.ui.workspace.colorpalette
(:require
[app.common.math :as mth]
[app.main.data.workspace.colors :as mdc]
[app.main.data.workspace :as udw]
[app.main.data.workspace.colors :as mdc]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.components.color-bullet :as cb]
@ -16,11 +17,9 @@
[app.main.ui.context :as ctx]
[app.main.ui.icons :as i]
[app.util.color :as uc]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t]]
[app.util.i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.object :as obj]
[beicon.core :as rx]
[cuerdas.core :as str]
[goog.events :as events]
[okulary.core :as l]
@ -50,7 +49,7 @@
[{:keys [color size local?]}]
(let [select-color
(fn [event]
(let [ids (get-in @st/state [:workspace-local :selected])]
(let [ids (wsh/lookup-selected @st/state)]
(if (kbd/shift? event)
(st/emit! (mdc/change-stroke ids (merge uc/empty-color color)))
(st/emit! (mdc/change-fill ids (merge uc/empty-color color))))))]
@ -74,8 +73,6 @@
close-fn #(st/emit! (udw/toggle-layout-flags :colorpalette))
container (mf/use-ref nil)
locale (mf/deref i18n/locale)
on-left-arrow-click
(mf/use-callback
(mf/deps max-offset visible)
@ -143,7 +140,7 @@
[:li.palette-library
{:on-click #(st/emit! (mdc/change-palette-selected :file))}
(when (= selected :file) i/tick)
[:div.library-name (str (t locale "workspace.libraries.colors.file-library")
[:div.library-name (str (tr "workspace.libraries.colors.file-library")
(str/format " (%s)" (count file-colors)))]
[:div.color-sample
(for [[idx color] (map-indexed vector (take 7 (vals file-colors))) ]
@ -153,7 +150,7 @@
[:li.palette-library
{:on-click #(st/emit! (mdc/change-palette-selected :recent))}
(when (= selected :recent) i/tick)
[:div.library-name (str (t locale "workspace.libraries.colors.recent-colors")
[:div.library-name (str (tr "workspace.libraries.colors.recent-colors")
(str/format " (%s)" (count recent-colors)))]
[:div.color-sample
(for [[idx color] (map-indexed vector (take 7 (reverse recent-colors))) ]
@ -165,12 +162,12 @@
[:li
{:on-click #(st/emit! (mdc/change-palette-size :big))}
(when (= size :big) i/tick)
(t locale "workspace.libraries.colors.big-thumbnails")]
(tr "workspace.libraries.colors.big-thumbnails")]
[:li
{:on-click #(st/emit! (mdc/change-palette-size :small))}
(when (= size :small) i/tick)
(t locale "workspace.libraries.colors.small-thumbnails")]]]
(tr "workspace.libraries.colors.small-thumbnails")]]]
[:div.color-palette-actions
{:on-click #(swap! state assoc :show-menu true)}

View file

@ -21,6 +21,7 @@
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.undo :as dwu]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.texts :as dwt]
[app.main.exports :as exports]
[app.main.refs :as refs]
@ -514,7 +515,7 @@
apply-color
(fn [color-id event]
(let [ids (get-in @st/state [:workspace-local :selected])]
(let [ids (wsh/lookup-selected @st/state)]
(if (kbd/shift? event)
(st/emit! (dc/change-stroke ids color))
(st/emit! (dc/change-fill ids color)))))
@ -713,7 +714,7 @@
apply-typography
(fn [typography event]
(let [ids (get-in @st/state [:workspace-local :selected])
(let [ids (wsh/lookup-selected @st/state)
attrs (merge
{:typography-ref-file file-id
:typography-ref-id (:id typography)}

View file

@ -35,7 +35,7 @@
;; --- Viewport
(mf/defc viewport
[{:keys [local layout file] :as props}]
[{:keys [local selected layout file] :as props}]
(let [;; When adding data from workspace-local revisit `app.main.ui.workspace` to check
;; that the new parameter is sent
{:keys [edit-path
@ -44,7 +44,6 @@
options-mode
panning
picking-color?
selected
selrect
show-distances?
tooltip
@ -53,7 +52,6 @@
vport
zoom]} local
;; CONTEXT
page-id (mf/use-ctx ctx/current-page-id)

View file

@ -1,18 +1,20 @@
(ns app.test-components-basic
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer [pprint]]
[clojure.stacktrace :as stk]
[beicon.core :as rx]
[linked.core :as lks]
[app.test-helpers.events :as the]
[app.test-helpers.pages :as thp]
[app.test-helpers.libraries :as thl]
[app.common.geom.point :as gpt]
(:require
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.pages.helpers :as cph]
[app.main.data.workspace :as dw]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.libraries-helpers :as dwlh]))
[app.main.data.workspace.libraries-helpers :as dwlh]
[app.main.data.workspace.state-helpers :as wsh]
[app.test-helpers.events :as the]
[app.test-helpers.libraries :as thl]
[app.test-helpers.pages :as thp]
[beicon.core :as rx]
[cljs.pprint :refer [pprint]]
[cljs.test :as t :include-macros true]
[clojure.stacktrace :as stk]
[linked.core :as lks]))
(t/use-fixtures :each
{:before thp/reset-idmap!})
@ -307,8 +309,8 @@
(gpt/point 100 100)))
(rx/do
(fn [new-state]
(let [new-instance-id (-> (get-in new-state
[:workspace-local :selected])
(let [new-instance-id (-> new-state
wsh/lookup-selected
first)
[[instance2 shape2]