mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
🐛 Fix variants events (#7320)
* 🐛 Add missing event add-component-to-variant * 🐛 Fix event apply-tokens, param applied-to-variant * 🐛 Fix missing case on event "add new variant" * 🐛 Fix event combine-as-variants * 🐛 Fix event variant-edit-property-name * 🐛 On variants events, change trigger for origin * 🐛 Split combine-as-variants to not have an optional first parameter
This commit is contained in:
parent
c62fadac47
commit
18d5b84b00
@ -887,6 +887,12 @@
|
|||||||
(pcb/update-shapes [parent-id]
|
(pcb/update-shapes [parent-id]
|
||||||
#(ctl/add-children-to-cell % selected all-objects drop-cell)))
|
#(ctl/add-children-to-cell % selected all-objects drop-cell)))
|
||||||
|
|
||||||
|
add-component-to-variant? (and
|
||||||
|
;; Any of the shapes is a head
|
||||||
|
(some ctc/instance-head? orig-shapes)
|
||||||
|
;; Any ancestor of the destination parent is a variant
|
||||||
|
(->> (cfh/get-parents-with-self page-objects parent-id)
|
||||||
|
(some ctc/is-variant?)))
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
@ -895,10 +901,7 @@
|
|||||||
(let [parent-type (cfh/get-shape-type all-objects (:parent-id shape))
|
(let [parent-type (cfh/get-shape-type all-objects (:parent-id shape))
|
||||||
external-lib? (not= file-id (:component-file shape))
|
external-lib? (not= file-id (:component-file shape))
|
||||||
component (ctn/get-component-from-shape shape libraries)
|
component (ctn/get-component-from-shape shape libraries)
|
||||||
origin "workspace:paste"
|
origin "workspace:paste"]
|
||||||
any-parent-is-variant (->> (cfh/get-parents-with-self all-objects (:parent-id shape))
|
|
||||||
(some ctc/is-variant?)
|
|
||||||
boolean)]
|
|
||||||
|
|
||||||
;; NOTE: we don't emit the create-shape event all the time for
|
;; NOTE: we don't emit the create-shape event all the time for
|
||||||
;; avoid send a lot of events (that are not necessary); this
|
;; avoid send a lot of events (that are not necessary); this
|
||||||
@ -909,8 +912,7 @@
|
|||||||
:is-external-library external-lib?
|
:is-external-library external-lib?
|
||||||
:type (get shape :type)
|
:type (get shape :type)
|
||||||
:parent-type parent-type
|
:parent-type parent-type
|
||||||
:is-variant (ctc/is-variant? component)
|
:is-variant (ctc/is-variant? component)})
|
||||||
:any-parent-is-variant any-parent-is-variant})
|
|
||||||
(if (cfh/has-layout? objects (:parent-id shape))
|
(if (cfh/has-layout? objects (:parent-id shape))
|
||||||
(ev/event {::ev/name "layout-add-element"
|
(ev/event {::ev/name "layout-add-element"
|
||||||
::ev/origin origin
|
::ev/origin origin
|
||||||
@ -925,7 +927,9 @@
|
|||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes)
|
||||||
(dws/select-shapes selected)
|
(dws/select-shapes selected)
|
||||||
(ptk/data-event :layout/update {:ids [frame-id]})
|
(ptk/data-event :layout/update {:ids [frame-id]})
|
||||||
(dwu/commit-undo-transaction undo-id))))))))
|
(dwu/commit-undo-transaction undo-id)
|
||||||
|
(when add-component-to-variant?
|
||||||
|
(ptk/event ::ev/event {::ev/name "add-component-to-variant"})))))))))
|
||||||
|
|
||||||
(defn- as-content [text]
|
(defn- as-content [text]
|
||||||
(let [paragraphs (->> (str/lines text)
|
(let [paragraphs (->> (str/lines text)
|
||||||
|
|||||||
@ -592,9 +592,6 @@
|
|||||||
page
|
page
|
||||||
libraries)
|
libraries)
|
||||||
component (ctn/get-component-from-shape new-shape libraries)
|
component (ctn/get-component-from-shape new-shape libraries)
|
||||||
any-parent-is-variant (->> (cfh/get-parents-with-self objects (:parent-id new-shape))
|
|
||||||
(some ctk/is-variant?)
|
|
||||||
boolean)
|
|
||||||
|
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
|
|
||||||
@ -605,8 +602,7 @@
|
|||||||
{::ev/name "use-library-component"
|
{::ev/name "use-library-component"
|
||||||
::ev/origin origin
|
::ev/origin origin
|
||||||
:external-library (not= file-id current-file-id)
|
:external-library (not= file-id current-file-id)
|
||||||
:is-variant (ctk/is-variant? component)
|
:is-variant (ctk/is-variant? component)})
|
||||||
:any-parent-is-variant any-parent-is-variant})
|
|
||||||
(dwu/start-undo-transaction undo-id)
|
(dwu/start-undo-transaction undo-id)
|
||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes)
|
||||||
(ptk/data-event :layout/update {:ids [(:id new-shape)]})
|
(ptk/data-event :layout/update {:ids [(:id new-shape)]})
|
||||||
|
|||||||
@ -486,11 +486,7 @@
|
|||||||
parent-type (cfh/get-shape-type objects (:parent-id shape))
|
parent-type (cfh/get-shape-type objects (:parent-id shape))
|
||||||
external-lib? (not= file-id (:component-file shape))
|
external-lib? (not= file-id (:component-file shape))
|
||||||
component (ctn/get-component-from-shape shape libraries)
|
component (ctn/get-component-from-shape shape libraries)
|
||||||
origin "workspace:duplicate-shapes"
|
origin "workspace:duplicate-shapes"]
|
||||||
|
|
||||||
any-parent-is-variant (->> (cfh/get-parents-with-self objects (:parent-id shape))
|
|
||||||
(some ctk/is-variant?)
|
|
||||||
boolean)]
|
|
||||||
|
|
||||||
;; NOTE: we don't emit the create-shape event all the time for
|
;; NOTE: we don't emit the create-shape event all the time for
|
||||||
;; avoid send a lot of events (that are not necessary); this
|
;; avoid send a lot of events (that are not necessary); this
|
||||||
@ -501,8 +497,7 @@
|
|||||||
:is-external-library external-lib?
|
:is-external-library external-lib?
|
||||||
:type (get shape :type)
|
:type (get shape :type)
|
||||||
:parent-type parent-type
|
:parent-type parent-type
|
||||||
:is-variant (ctk/is-variant? component)
|
:is-variant (ctk/is-variant? component)})
|
||||||
:any-parent-is-variant any-parent-is-variant})
|
|
||||||
(if (cfh/has-layout? objects (:parent-id shape))
|
(if (cfh/has-layout? objects (:parent-id shape))
|
||||||
(ev/event {::ev/name "layout-add-element"
|
(ev/event {::ev/name "layout-add-element"
|
||||||
::ev/origin origin
|
::ev/origin origin
|
||||||
|
|||||||
@ -235,7 +235,6 @@
|
|||||||
parent-id (:id (ctn/get-first-valid-parent objects parent-id)) ;; We don't want to change the structure of component copies
|
parent-id (:id (ctn/get-first-valid-parent objects parent-id)) ;; We don't want to change the structure of component copies
|
||||||
frame-id (:id (ctn/get-first-valid-parent objects frame-id))
|
frame-id (:id (ctn/get-first-valid-parent objects frame-id))
|
||||||
|
|
||||||
|
|
||||||
shape (cts/setup-shape
|
shape (cts/setup-shape
|
||||||
(-> attrs
|
(-> attrs
|
||||||
(assoc :type type)
|
(assoc :type type)
|
||||||
@ -312,7 +311,6 @@
|
|||||||
(get objects)
|
(get objects)
|
||||||
(ctc/is-variant?))))]
|
(ctc/is-variant?))))]
|
||||||
|
|
||||||
|
|
||||||
(rx/of (create-artboard-from-shapes selected id parent-id index name delta)))))))
|
(rx/of (create-artboard-from-shapes selected id parent-id index name delta)))))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
@ -362,6 +360,7 @@
|
|||||||
|
|
||||||
;; FIXME: this need to be refactored
|
;; FIXME: this need to be refactored
|
||||||
|
|
||||||
|
|
||||||
(defn toggle-file-thumbnail-selected
|
(defn toggle-file-thumbnail-selected
|
||||||
[]
|
[]
|
||||||
(ptk/reify ::toggle-file-thumbnail-selected
|
(ptk/reify ::toggle-file-thumbnail-selected
|
||||||
@ -397,6 +396,7 @@
|
|||||||
|
|
||||||
;; --- Change Shape Order (D&D Ordering)
|
;; --- Change Shape Order (D&D Ordering)
|
||||||
|
|
||||||
|
|
||||||
(defn relocate-shapes
|
(defn relocate-shapes
|
||||||
[ids parent-id to-index & [ignore-parents?]]
|
[ids parent-id to-index & [ignore-parents?]]
|
||||||
(dm/assert! (every? uuid? ids))
|
(dm/assert! (every? uuid? ids))
|
||||||
@ -428,10 +428,28 @@
|
|||||||
to-index
|
to-index
|
||||||
ids
|
ids
|
||||||
:ignore-parents? ignore-parents?))
|
:ignore-parents? ignore-parents?))
|
||||||
|
|
||||||
|
add-component-to-variant? (and
|
||||||
|
;; Any of the shapes is a head
|
||||||
|
(some (comp ctc/instance-head? objects) ids)
|
||||||
|
;; Any ancestor of the destination parent is a variant
|
||||||
|
(->> (cfh/get-parents-with-self objects parent-id)
|
||||||
|
(some ctc/is-variant?)))
|
||||||
|
|
||||||
|
add-new-variant? (and
|
||||||
|
;; The parent is a variant container
|
||||||
|
(-> parent-id objects ctc/is-variant-container?)
|
||||||
|
;; Any of the shapes is a main instance
|
||||||
|
(some (comp ctc/main-instance? objects) ids))
|
||||||
|
|
||||||
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 {:ids (concat all-parents ids)})
|
(ptk/data-event :layout/update {:ids (concat all-parents ids)})
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id)
|
||||||
|
(when add-component-to-variant?
|
||||||
|
(ev/event {::ev/name "add-component-to-variant"}))
|
||||||
|
(when add-new-variant?
|
||||||
|
(ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:move-shapes-in-layers-tab"})))))))
|
||||||
|
|||||||
@ -489,7 +489,7 @@
|
|||||||
(some ctt/spacing-margin-keys attributes))
|
(some ctt/spacing-margin-keys attributes))
|
||||||
(ctt/any-appliable-attr? attributes (:type shape))))))
|
(ctt/any-appliable-attr? attributes (:type shape))))))
|
||||||
shape-ids (d/nilv (keys shapes) [])
|
shape-ids (d/nilv (keys shapes) [])
|
||||||
any-variant? (->> shapes (some ctk/is-variant?) boolean)
|
any-variant? (->> shapes vals (some ctk/is-variant?) boolean)
|
||||||
|
|
||||||
resolved-value (get-in resolved-tokens [(cft/token-identifier token) :resolved-value])
|
resolved-value (get-in resolved-tokens [(cft/token-identifier token) :resolved-value])
|
||||||
tokenized-attributes (cft/attributes-map attributes token)
|
tokenized-attributes (cft/attributes-map attributes token)
|
||||||
|
|||||||
@ -295,7 +295,6 @@
|
|||||||
(rx/map #(resize shape initial-position layout %))
|
(rx/map #(resize shape initial-position layout %))
|
||||||
(rx/share))
|
(rx/share))
|
||||||
|
|
||||||
|
|
||||||
modifiers-stream
|
modifiers-stream
|
||||||
(if (features/active-feature? state "render-wasm/v1")
|
(if (features/active-feature? state "render-wasm/v1")
|
||||||
(rx/merge
|
(rx/merge
|
||||||
@ -1024,7 +1023,6 @@
|
|||||||
delta (calculate-delta position bbox frame)
|
delta (calculate-delta position bbox frame)
|
||||||
modifiers (dwm/create-modif-tree [id] (ctm/move-modifiers delta))]
|
modifiers (dwm/create-modif-tree [id] (ctm/move-modifiers delta))]
|
||||||
|
|
||||||
|
|
||||||
(if (features/active-feature? state "render-wasm/v1")
|
(if (features/active-feature? state "render-wasm/v1")
|
||||||
(rx/of (dwm/apply-wasm-modifiers modifiers
|
(rx/of (dwm/apply-wasm-modifiers modifiers
|
||||||
{:ignore-constraints false
|
{:ignore-constraints false
|
||||||
@ -1105,7 +1103,19 @@
|
|||||||
frame-id
|
frame-id
|
||||||
drop-index
|
drop-index
|
||||||
ids
|
ids
|
||||||
:cell cell))]
|
:cell cell))
|
||||||
|
|
||||||
|
add-component-to-variant? (and
|
||||||
|
;; Any of the shapes is a head
|
||||||
|
(some (comp ctk/instance-head? objects) ids)
|
||||||
|
;; Any ancestor of the destination parent is a variant
|
||||||
|
(->> (cfh/get-parents-with-self objects frame-id)
|
||||||
|
(some ctk/is-variant?)))
|
||||||
|
add-new-variant? (and
|
||||||
|
;; The parent is a variant container
|
||||||
|
(-> frame-id objects ctk/is-variant-container?)
|
||||||
|
;; Any of the shapes is a main instance
|
||||||
|
(some (comp ctk/main-instance? objects) ids))]
|
||||||
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(let [shapes (mapv #(get objects %) ids)
|
(let [shapes (mapv #(get objects %) ids)
|
||||||
@ -1120,7 +1130,11 @@
|
|||||||
|
|
||||||
(when (and (some? frame-id) (d/not-empty? changes))
|
(when (and (some? frame-id) (d/not-empty? changes))
|
||||||
(rx/of (dch/commit-changes changes)
|
(rx/of (dch/commit-changes changes)
|
||||||
(dwc/expand-collapse frame-id))))))))
|
(dwc/expand-collapse frame-id)))
|
||||||
|
(when add-component-to-variant?
|
||||||
|
(rx/of (ev/event {::ev/name "add-component-to-variant"})))
|
||||||
|
(when add-new-variant?
|
||||||
|
(rx/of (ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:move-shapes-to-frame"}))))))))
|
||||||
|
|
||||||
(defn- get-displacement
|
(defn- get-displacement
|
||||||
"Retrieve the correct displacement delta point for the
|
"Retrieve the correct displacement delta point for the
|
||||||
@ -1135,6 +1149,7 @@
|
|||||||
|
|
||||||
;; -- Flip ----------------------------------------------------------
|
;; -- Flip ----------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
(defn flip-horizontal-selected
|
(defn flip-horizontal-selected
|
||||||
([]
|
([]
|
||||||
(flip-horizontal-selected nil))
|
(flip-horizontal-selected nil))
|
||||||
@ -1152,7 +1167,6 @@
|
|||||||
center (grc/rect->center selrect)
|
center (grc/rect->center selrect)
|
||||||
modifiers (dwm/create-modif-tree selected (ctm/resize-modifiers (gpt/point -1.0 1.0) center))]
|
modifiers (dwm/create-modif-tree selected (ctm/resize-modifiers (gpt/point -1.0 1.0) center))]
|
||||||
|
|
||||||
|
|
||||||
(if (features/active-feature? state "render-wasm/v1")
|
(if (features/active-feature? state "render-wasm/v1")
|
||||||
(rx/of (dwm/apply-wasm-modifiers modifiers {:ignore-snap-pixel true}))
|
(rx/of (dwm/apply-wasm-modifiers modifiers {:ignore-snap-pixel true}))
|
||||||
(rx/of (dwm/apply-modifiers {:modifiers modifiers :ignore-snap-pixel true}))))))))
|
(rx/of (dwm/apply-modifiers {:modifiers modifiers :ignore-snap-pixel true}))))))))
|
||||||
|
|||||||
@ -87,9 +87,9 @@
|
|||||||
|
|
||||||
(rx/of
|
(rx/of
|
||||||
(when (or (seq properties-to-remove) (seq properties-to-update))
|
(when (or (seq properties-to-remove) (seq properties-to-update))
|
||||||
(ptk/event ::ev/event {::ev/name "variant-edit-property-value" :trigger "rename-in-layers"}))
|
(ev/event {::ev/name "variant-edit-property-value" ::ev/origin "workspace:rename-in-layers"}))
|
||||||
(when (seq properties-to-add)
|
(when (seq properties-to-add)
|
||||||
(ptk/event ::ev/event {::ev/name "variant-add-property" :trigger "rename-in-layers"}))
|
(ev/event {::ev/name "variant-add-property" ::ev/origin "workspace:rename-in-layers"}))
|
||||||
(dwu/start-undo-transaction undo-id)
|
(dwu/start-undo-transaction undo-id)
|
||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes)
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dwu/commit-undo-transaction undo-id))))))
|
||||||
@ -97,7 +97,7 @@
|
|||||||
(defn update-property-name
|
(defn update-property-name
|
||||||
"Update the variant property name on the position pos
|
"Update the variant property name on the position pos
|
||||||
in all the components with this variant-id"
|
in all the components with this variant-id"
|
||||||
[variant-id pos new-name]
|
[variant-id pos new-name {:keys [trigger]}]
|
||||||
(ptk/reify ::update-property-name
|
(ptk/reify ::update-property-name
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
@ -106,15 +106,22 @@
|
|||||||
objects (-> (dsh/get-page data page-id)
|
objects (-> (dsh/get-page data page-id)
|
||||||
(get :objects))
|
(get :objects))
|
||||||
|
|
||||||
|
related-components (cfv/find-variant-components data objects variant-id)
|
||||||
|
|
||||||
|
props (-> related-components last :variant-properties)
|
||||||
|
prop-name (-> props (nth pos) :name)
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it page-id)
|
changes (-> (pcb/empty-changes it page-id)
|
||||||
(pcb/with-objects objects)
|
(pcb/with-objects objects)
|
||||||
(pcb/with-library-data data)
|
(pcb/with-library-data data)
|
||||||
(clvp/generate-update-property-name variant-id pos new-name))
|
(clvp/generate-update-property-name variant-id pos new-name))
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
(rx/of
|
(when (not= prop-name new-name)
|
||||||
(dwu/start-undo-transaction undo-id)
|
(rx/of
|
||||||
(dch/commit-changes changes)
|
(dwu/start-undo-transaction undo-id)
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
(dch/commit-changes changes)
|
||||||
|
(dwu/commit-undo-transaction undo-id)
|
||||||
|
(ev/event {::ev/name "variant-edit-property-name" ::ev/origin trigger})))))))
|
||||||
|
|
||||||
(defn update-property-value
|
(defn update-property-value
|
||||||
"Updates the variant property value on the position pos in a component"
|
"Updates the variant property value on the position pos in a component"
|
||||||
@ -225,7 +232,7 @@
|
|||||||
|
|
||||||
(when (seq (:redo-changes changes))
|
(when (seq (:redo-changes changes))
|
||||||
(rx/of
|
(rx/of
|
||||||
(ptk/event ::ev/event {::ev/name "variant-remove-property" :trigger "rename-in-layers"})
|
(ev/event {::ev/name "variant-remove-property" ::ev/origin "workspace:rename-in-layers"})
|
||||||
(dwu/start-undo-transaction undo-id)
|
(dwu/start-undo-transaction undo-id)
|
||||||
(dch/commit-changes changes)
|
(dch/commit-changes changes)
|
||||||
(dwu/commit-undo-transaction undo-id)))))))
|
(dwu/commit-undo-transaction undo-id)))))))
|
||||||
@ -466,13 +473,13 @@
|
|||||||
(cond
|
(cond
|
||||||
transform-in-variant?
|
transform-in-variant?
|
||||||
(rx/of
|
(rx/of
|
||||||
(ptk/event ::ev/event {::ev/name "transform-in-variant" :trigger "shortcut"})
|
(ev/event {::ev/name "transform-in-variant" ::ev/origin "workspace:shortcut"})
|
||||||
(transform-in-variant (:id first-shape)))
|
(transform-in-variant (:id first-shape)))
|
||||||
|
|
||||||
add-new-variant?
|
add-new-variant?
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of
|
(rx/of
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-variant" :trigger "shortcut-create-component"})
|
(ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:shortcut-create-component"})
|
||||||
(dwu/start-undo-transaction undo-id))
|
(dwu/start-undo-transaction undo-id))
|
||||||
(rx/from (map add-new-variant selected-ids))
|
(rx/from (map add-new-variant selected-ids))
|
||||||
(rx/of (dwu/commit-undo-transaction undo-id)))
|
(rx/of (dwu/commit-undo-transaction undo-id)))
|
||||||
@ -494,7 +501,7 @@
|
|||||||
(if add-new-variant?
|
(if add-new-variant?
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(rx/of
|
(rx/of
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-variant" :trigger "shortcut-duplicate"})
|
(ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:shortcut-duplicate"})
|
||||||
(dwu/start-undo-transaction undo-id)
|
(dwu/start-undo-transaction undo-id)
|
||||||
(add-new-variant (first selected-ids) false))
|
(add-new-variant (first selected-ids) false))
|
||||||
(rx/from (map #(add-new-variant % true) (rest selected-ids)))
|
(rx/from (map #(add-new-variant % true) (rest selected-ids)))
|
||||||
@ -563,79 +570,86 @@
|
|||||||
vec))
|
vec))
|
||||||
|
|
||||||
(defn combine-as-variants
|
(defn combine-as-variants
|
||||||
([]
|
[ids {:keys [page-id trigger]}]
|
||||||
(combine-as-variants nil {}))
|
(ptk/reify ::combine-as-variants
|
||||||
([selected {:keys [page-id]}]
|
ptk/WatchEvent
|
||||||
(ptk/reify ::combine-as-variants
|
(watch [_ state stream]
|
||||||
ptk/WatchEvent
|
(let [current-page (:current-page-id state)
|
||||||
(watch [_ state stream]
|
|
||||||
(let [current-page (:current-page-id state)
|
|
||||||
|
|
||||||
combine
|
combine
|
||||||
(fn [current-page]
|
(fn [current-page]
|
||||||
(let [objects (dsh/lookup-page-objects state current-page)
|
(let [objects (dsh/lookup-page-objects state current-page)
|
||||||
selected (->> (or selected (dsh/lookup-selected state))
|
ids (->> ids
|
||||||
(cfh/clean-loops objects)
|
(cfh/clean-loops objects)
|
||||||
(remove (fn [id]
|
(remove (fn [id]
|
||||||
(let [shape (get objects id)]
|
(let [shape (get objects id)]
|
||||||
(or (not (ctc/main-instance? shape))
|
(or (not (ctc/main-instance? shape))
|
||||||
(ctc/is-variant? shape))))))]
|
(ctc/is-variant? shape))))))]
|
||||||
(when (> (count selected) 1)
|
(when (> (count ids) 1)
|
||||||
(let [shapes (mapv #(get objects %) selected)
|
(let [shapes (mapv #(get objects %) ids)
|
||||||
rect (bounding-rect shapes)
|
rect (bounding-rect shapes)
|
||||||
prefix (->> shapes
|
prefix (->> shapes
|
||||||
(mapv #(cfh/split-path (:name %)))
|
(mapv #(cfh/split-path (:name %)))
|
||||||
(common-prefix))
|
(common-prefix))
|
||||||
;; When the common parent is root, add a wrapper
|
;; When the common parent is root, add a wrapper
|
||||||
add-wrapper? (empty? prefix)
|
add-wrapper? (empty? prefix)
|
||||||
first-shape (first shapes)
|
first-shape (first shapes)
|
||||||
delta (gpt/point (- (:x rect) (:x first-shape) 30)
|
delta (gpt/point (- (:x rect) (:x first-shape) 30)
|
||||||
(- (:y rect) (:y first-shape) 30))
|
(- (:y rect) (:y first-shape) 30))
|
||||||
common-parent (->> selected
|
common-parent (->> ids
|
||||||
(mapv #(-> (cfh/get-parent-ids objects %) reverse))
|
(mapv #(-> (cfh/get-parent-ids objects %) reverse))
|
||||||
common-prefix
|
common-prefix
|
||||||
last)
|
last)
|
||||||
index (-> (get objects common-parent)
|
index (-> (get objects common-parent)
|
||||||
:shapes
|
:shapes
|
||||||
count
|
count
|
||||||
inc)
|
inc)
|
||||||
variant-id (uuid/next)
|
variant-id (uuid/next)
|
||||||
undo-id (js/Symbol)]
|
undo-id (js/Symbol)]
|
||||||
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(if (and page-id (not= current-page page-id))
|
(if (and page-id (not= current-page page-id))
|
||||||
(rx/of (dcm/go-to-workspace :page-id page-id))
|
(rx/of (dcm/go-to-workspace :page-id page-id))
|
||||||
(rx/empty))
|
(rx/empty))
|
||||||
|
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
(transform-in-variant (first selected) variant-id delta prefix add-wrapper? false false)
|
(transform-in-variant (first ids) variant-id delta prefix add-wrapper? false false)
|
||||||
(dwsh/relocate-shapes (into #{} (-> selected rest reverse)) variant-id 0)
|
(dwsh/relocate-shapes (into #{} (-> ids rest reverse)) variant-id 0)
|
||||||
(dwsh/update-shapes selected #(-> %
|
(dwsh/update-shapes ids #(-> %
|
||||||
(assoc :constraints-h :left)
|
(assoc :constraints-h :left)
|
||||||
(assoc :constraints-v :top)
|
(assoc :constraints-v :top)
|
||||||
(assoc :fixed-scroll false)))
|
(assoc :fixed-scroll false)))
|
||||||
(dwsh/relocate-shapes #{variant-id} common-parent index)
|
(dwsh/relocate-shapes #{variant-id} common-parent index)
|
||||||
(dwt/update-dimensions [variant-id] :width (+ (:width rect) 60))
|
(dwt/update-dimensions [variant-id] :width (+ (:width rect) 60))
|
||||||
(dwt/update-dimensions [variant-id] :height (+ (:height rect) 60)))
|
(dwt/update-dimensions [variant-id] :height (+ (:height rect) 60))
|
||||||
|
(ev/event {::ev/name "combine-as-variants" ::ev/origin trigger :number-of-combined (count ids)}))
|
||||||
|
|
||||||
;; NOTE: we need to schedule a commit into a
|
;; NOTE: we need to schedule a commit into a
|
||||||
;; microtask for ensure that all the scheduled
|
;; microtask for ensure that all the scheduled
|
||||||
;; microtask of previous events execute before the
|
;; microtask of previous events execute before the
|
||||||
;; commit
|
;; commit
|
||||||
(->> (rx/of (dwu/commit-undo-transaction undo-id))
|
(->> (rx/of (dwu/commit-undo-transaction undo-id))
|
||||||
(rx/observe-on :async)))))))
|
(rx/observe-on :async)))))))
|
||||||
|
|
||||||
redirect-to-page
|
redirect-to-page
|
||||||
(fn [page-id]
|
(fn [page-id]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter (ptk/type? ::dwpg/initialize-page))
|
(rx/filter (ptk/type? ::dwpg/initialize-page))
|
||||||
(rx/take 1)
|
(rx/take 1)
|
||||||
(rx/observe-on :async)
|
(rx/observe-on :async)
|
||||||
(rx/mapcat (fn [_] (combine page-id))))
|
(rx/mapcat (fn [_] (combine page-id))))
|
||||||
(rx/of (dcm/go-to-workspace :page-id page-id))))]
|
(rx/of (dcm/go-to-workspace :page-id page-id))))]
|
||||||
|
|
||||||
(if (and page-id (not= page-id current-page))
|
(if (and page-id (not= page-id current-page))
|
||||||
(redirect-to-page page-id)
|
(redirect-to-page page-id)
|
||||||
(combine current-page)))))))
|
(combine current-page))))))
|
||||||
|
|
||||||
|
(defn combine-selected-as-variants
|
||||||
|
[options]
|
||||||
|
(ptk/reify ::combine-selected-as-variants
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state _]
|
||||||
|
(let [selected (dsh/lookup-selected state)]
|
||||||
|
(rx/of (combine-as-variants selected options))))))
|
||||||
|
|
||||||
|
|||||||
@ -576,12 +576,11 @@
|
|||||||
do-add-component (mf/use-fn #(st/emit! (dwl/add-component)))
|
do-add-component (mf/use-fn #(st/emit! (dwl/add-component)))
|
||||||
do-add-multiple-components (mf/use-fn #(st/emit! (dwl/add-multiple-components)))
|
do-add-multiple-components (mf/use-fn #(st/emit! (dwl/add-multiple-components)))
|
||||||
do-combine-as-variants (mf/use-fn #(st/emit!
|
do-combine-as-variants (mf/use-fn #(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "combine-as-variants" :trigger "context-menu-component"})
|
(dwv/combine-selected-as-variants {:trigger "workspace:context-menu-component"})))
|
||||||
(dwv/combine-as-variants)))
|
|
||||||
do-add-variant (mf/use-fn
|
do-add-variant (mf/use-fn
|
||||||
(mf/deps shapes)
|
(mf/deps shapes)
|
||||||
#(st/emit!
|
#(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-variant" :trigger "context-menu-component"})
|
(ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:context-menu-component"})
|
||||||
(dwv/add-new-variant (:id (first shapes)))))]
|
(dwv/add-new-variant (:id (first shapes)))))]
|
||||||
[:*
|
[:*
|
||||||
(when can-make-component ;; We don't want to change the structure of component copies
|
(when can-make-component ;; We don't want to change the structure of component copies
|
||||||
@ -802,6 +801,7 @@
|
|||||||
|
|
||||||
;; FIXME: optimize because it is rendered always
|
;; FIXME: optimize because it is rendered always
|
||||||
|
|
||||||
|
|
||||||
(mf/defc context-menu*
|
(mf/defc context-menu*
|
||||||
[]
|
[]
|
||||||
(let [mdata (mf/deref menu-ref)
|
(let [mdata (mf/deref menu-ref)
|
||||||
|
|||||||
@ -39,7 +39,6 @@
|
|||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.v2.core :as ptk]
|
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(def assets-filters (mf/create-context nil))
|
(def assets-filters (mf/create-context nil))
|
||||||
@ -357,6 +356,8 @@
|
|||||||
|
|
||||||
|
|
||||||
;; For when it's only one shape
|
;; For when it's only one shape
|
||||||
|
|
||||||
|
|
||||||
shape (first shapes)
|
shape (first shapes)
|
||||||
shape-id (:id shape)
|
shape-id (:id shape)
|
||||||
|
|
||||||
@ -442,17 +443,17 @@
|
|||||||
do-add-variant
|
do-add-variant
|
||||||
#(if (ctk/is-variant? shape)
|
#(if (ctk/is-variant? shape)
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-variant"
|
(ev/event {::ev/name "add-new-variant"
|
||||||
:trigger (if for-design-tab? "design-tab-menu-variant" "context-menu-variant")})
|
::ev/origin (if for-design-tab? "workspace:design-tab-menu-variant" "workspace:context-menu-variant")})
|
||||||
(dwv/add-new-variant shape-id))
|
(dwv/add-new-variant shape-id))
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "transform-in-variant"
|
(ev/event {::ev/name "transform-in-variant"
|
||||||
:trigger (if for-design-tab? "design-tab-menu" "context-menu")})
|
::ev/origin (if for-design-tab? "workspace:design-tab-menu" "workspace:context-menu")})
|
||||||
(dwv/transform-in-variant shape-id)))
|
(dwv/transform-in-variant shape-id)))
|
||||||
|
|
||||||
do-add-new-property
|
do-add-new-property
|
||||||
#(st/emit!
|
#(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-property" :trigger "design-tab-menu-variant"})
|
(ev/event {::ev/name "add-new-property" ::ev/origin "workspace:design-tab-menu-variant"})
|
||||||
(dwv/add-new-property variant-id {:property-value "Value 1" :editing? true}))
|
(dwv/add-new-property variant-id {:property-value "Value 1" :editing? true}))
|
||||||
|
|
||||||
do-show-local-component
|
do-show-local-component
|
||||||
|
|||||||
@ -176,7 +176,6 @@
|
|||||||
:title (tr "workspace.assets.components.num-variants" num-variants)}
|
:title (tr "workspace.assets.components.num-variants" num-variants)}
|
||||||
[:> icon* {:icon-id i/variant :size "s"}]])])]))
|
[:> icon* {:icon-id i/variant :size "s"}]])])]))
|
||||||
|
|
||||||
|
|
||||||
(defn- count-leaves
|
(defn- count-leaves
|
||||||
"Counts the total number of leaf elements in a nested map structure.
|
"Counts the total number of leaf elements in a nested map structure.
|
||||||
A leaf element is considered any element inside a vector."
|
A leaf element is considered any element inside a vector."
|
||||||
@ -202,7 +201,6 @@
|
|||||||
dragging* (mf/use-state false)
|
dragging* (mf/use-state false)
|
||||||
dragging? (deref dragging*)
|
dragging? (deref dragging*)
|
||||||
|
|
||||||
|
|
||||||
selected-paths (mf/with-memo [selected-full]
|
selected-paths (mf/with-memo [selected-full]
|
||||||
(into #{}
|
(into #{}
|
||||||
(comp (map :path) (d/nilv ""))
|
(comp (map :path) (d/nilv ""))
|
||||||
@ -262,7 +260,6 @@
|
|||||||
(when ^boolean dragging?
|
(when ^boolean dragging?
|
||||||
[:div {:class (stl/css :grid-placeholder)} "\u00A0"])
|
[:div {:class (stl/css :grid-placeholder)} "\u00A0"])
|
||||||
|
|
||||||
|
|
||||||
(when (and (empty? components)
|
(when (and (empty? components)
|
||||||
(some? groups)
|
(some? groups)
|
||||||
is-local)
|
is-local)
|
||||||
@ -506,9 +503,7 @@
|
|||||||
page-id (->> comps first :main-instance-page)]
|
page-id (->> comps first :main-instance-page)]
|
||||||
|
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "combine-as-variants" :trigger "context-menu-assets-group"})
|
(dwv/combine-as-variants ids {:page-id page-id :trigger "workspace:context-menu-assets-group"})))))
|
||||||
(dwv/combine-as-variants ids {:page-id page-id})))))
|
|
||||||
|
|
||||||
|
|
||||||
on-drag-start
|
on-drag-start
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@ -557,8 +552,7 @@
|
|||||||
ids (into #{} (map :main-instance-id selected-full))]
|
ids (into #{} (map :main-instance-id selected-full))]
|
||||||
|
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "combine-as-variants" :trigger "context-menu-assets"})
|
(dwv/combine-as-variants ids {:page-id page-id :trigger "workspace:context-menu-assets"})))))]
|
||||||
(dwv/combine-as-variants ids {:page-id page-id})))))]
|
|
||||||
|
|
||||||
[:& cmm/asset-section {:file-id file-id
|
[:& cmm/asset-section {:file-id file-id
|
||||||
:title (tr "workspace.assets.components")
|
:title (tr "workspace.assets.components")
|
||||||
|
|||||||
@ -47,7 +47,6 @@
|
|||||||
[app.util.timers :as tm]
|
[app.util.timers :as tm]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[okulary.core :as l]
|
[okulary.core :as l]
|
||||||
[potok.v2.core :as ptk]
|
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(def ref:annotations-state
|
(def ref:annotations-state
|
||||||
@ -342,7 +341,7 @@
|
|||||||
(let [value (d/nilv (str/trim value) "")]
|
(let [value (d/nilv (str/trim value) "")]
|
||||||
(doseq [id component-ids]
|
(doseq [id component-ids]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "variant-edit-property-value" :trigger "combo-design-tab"})
|
(ev/event {::ev/name "variant-edit-property-value" ::ev/origin "workspace:combo-design-tab"})
|
||||||
(dwv/update-property-value id pos value))
|
(dwv/update-property-value id pos value))
|
||||||
(st/emit! (dwv/update-error id))))))
|
(st/emit! (dwv/update-error id))))))
|
||||||
|
|
||||||
@ -356,8 +355,7 @@
|
|||||||
int)]
|
int)]
|
||||||
(when (seq value)
|
(when (seq value)
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "variant-edit-property-name" :trigger "design-tab-variant"})
|
(dwv/update-property-name variant-id pos value {:trigger "workspace:design-tab-variant"}))))))]
|
||||||
(dwv/update-property-name variant-id pos value))))))]
|
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
[:div {:class (stl/css :variant-property-list)}
|
[:div {:class (stl/css :variant-property-list)}
|
||||||
@ -895,22 +893,21 @@
|
|||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps id)
|
(mf/deps id)
|
||||||
#(st/emit!
|
#(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-variant" :trigger "button-design-tab-variant"})
|
(ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:button-design-tab-variant"})
|
||||||
(dwv/add-new-variant id)))
|
(dwv/add-new-variant id)))
|
||||||
|
|
||||||
add-new-property
|
add-new-property
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps shape)
|
(mf/deps shape)
|
||||||
#(st/emit!
|
#(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-property" :trigger "button-design-tab-variant"})
|
(ev/event {::ev/name "add-new-property" ::ev/origin "workspace:button-design-tab-variant"})
|
||||||
(dwv/add-new-property (:variant-id shape) {:property-value "Value 1"
|
(dwv/add-new-property (:variant-id shape) {:property-value "Value 1"
|
||||||
:editing? true})))
|
:editing? true})))
|
||||||
|
|
||||||
on-combine-as-variants
|
on-combine-as-variants
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
#(st/emit!
|
#(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "combine-as-variants" :trigger "button-design-tab"})
|
(dwv/combine-selected-as-variants {:trigger "workspace:button-design-tab"})))
|
||||||
(dwv/combine-as-variants)))
|
|
||||||
|
|
||||||
;; NOTE: function needed for force rerender from the bottom
|
;; NOTE: function needed for force rerender from the bottom
|
||||||
;; components. This is because `component-annotation`
|
;; components. This is because `component-annotation`
|
||||||
@ -1097,7 +1094,7 @@
|
|||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps shape)
|
(mf/deps shape)
|
||||||
(fn [trigger]
|
(fn [trigger]
|
||||||
(st/emit! (ptk/event ::ev/event {::ev/name "add-new-variant" :trigger trigger})
|
(st/emit! (ev/event {::ev/name "add-new-variant" ::ev/origin trigger})
|
||||||
(dwv/add-new-variant (:id shape)))))
|
(dwv/add-new-variant (:id shape)))))
|
||||||
|
|
||||||
add-new-property
|
add-new-property
|
||||||
@ -1105,16 +1102,16 @@
|
|||||||
(mf/deps variant-id)
|
(mf/deps variant-id)
|
||||||
(fn [trigger]
|
(fn [trigger]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "add-new-property" :trigger trigger})
|
(ev/event {::ev/name "add-new-property" ::ev/origin trigger})
|
||||||
(dwv/add-new-property variant-id {:property-value "Value 1"
|
(dwv/add-new-property variant-id {:property-value "Value 1"
|
||||||
:editing? true}))))
|
:editing? true}))))
|
||||||
|
|
||||||
menu-entries [{:title (tr "workspace.shape.menu.show-in-assets")
|
menu-entries [{:title (tr "workspace.shape.menu.show-in-assets")
|
||||||
:action show-in-assets-panel}
|
:action show-in-assets-panel}
|
||||||
{:title (tr "workspace.shape.menu.add-variant")
|
{:title (tr "workspace.shape.menu.add-variant")
|
||||||
:action (partial create-variant "design-tab-menu-component")}
|
:action (partial create-variant "workspace:design-tab-menu-component")}
|
||||||
{:title (tr "workspace.shape.menu.add-variant-property")
|
{:title (tr "workspace.shape.menu.add-variant-property")
|
||||||
:action (partial add-new-property "design-tab-menu-component")}]
|
:action (partial add-new-property "workspace:design-tab-menu-component")}]
|
||||||
|
|
||||||
toggle-content
|
toggle-content
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@ -1149,8 +1146,7 @@
|
|||||||
int)]
|
int)]
|
||||||
(when (seq value)
|
(when (seq value)
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "variant-edit-property-name" :trigger "design-tab-component"})
|
(dwv/update-property-name variant-id pos value {:trigger "workspace:design-tab-component"}))))))
|
||||||
(dwv/update-property-name variant-id pos value))))))
|
|
||||||
|
|
||||||
remove-property
|
remove-property
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
@ -1161,7 +1157,7 @@
|
|||||||
int)]
|
int)]
|
||||||
(when (> (count properties) 1)
|
(when (> (count properties) 1)
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ptk/event ::ev/event {::ev/name "variant-remove-property" :trigger "button-design-tab"})
|
(ev/event {::ev/name "variant-remove-property" ::ev/origin "workspace:button-design-tab"})
|
||||||
(dwv/remove-property variant-id pos))))))
|
(dwv/remove-property variant-id pos))))))
|
||||||
|
|
||||||
select-shapes-with-malformed
|
select-shapes-with-malformed
|
||||||
@ -1195,7 +1191,7 @@
|
|||||||
:icon i/help}]
|
:icon i/help}]
|
||||||
[:> icon-button* {:variant "ghost"
|
[:> icon-button* {:variant "ghost"
|
||||||
:aria-label (tr "workspace.shape.menu.add-variant")
|
:aria-label (tr "workspace.shape.menu.add-variant")
|
||||||
:on-click (partial create-variant "button-design-tab-component")
|
:on-click (partial create-variant "workspace:button-design-tab-component")
|
||||||
:icon i/variant}]]]]
|
:icon i/variant}]]]]
|
||||||
|
|
||||||
(when open?
|
(when open?
|
||||||
@ -1233,7 +1229,7 @@
|
|||||||
|
|
||||||
[:> icon-button* {:variant "ghost"
|
[:> icon-button* {:variant "ghost"
|
||||||
:aria-label (tr "workspace.shape.menu.add-variant-property")
|
:aria-label (tr "workspace.shape.menu.add-variant-property")
|
||||||
:on-click (partial add-new-property "button-design-tab-component")
|
:on-click (partial add-new-property "workspace:button-design-tab-component")
|
||||||
:icon i/add}]]
|
:icon i/add}]]
|
||||||
|
|
||||||
(when-not multi?
|
(when-not multi?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user