mirror of
https://github.com/penpot/penpot.git
synced 2025-06-05 07:41:37 +02:00
🎉 Add drag components in or out a variant container
This commit is contained in:
parent
6277db8d45
commit
014c297458
18 changed files with 613 additions and 206 deletions
|
@ -890,6 +890,7 @@
|
|||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state page-id)
|
||||
data (dsh/lookup-file-data state)
|
||||
|
||||
;; Ignore any shape whose parent is also intended to be moved
|
||||
ids (cfh/clean-loops objects ids)
|
||||
|
@ -899,13 +900,15 @@
|
|||
|
||||
all-parents (into #{parent-id} (map #(cfh/get-parent-id objects %)) ids)
|
||||
|
||||
changes (cls/generate-relocate (pcb/empty-changes it)
|
||||
objects
|
||||
parent-id
|
||||
page-id
|
||||
to-index
|
||||
ids
|
||||
:ignore-parents? ignore-parents?)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-page-id page-id)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/with-library-data data)
|
||||
(cls/generate-relocate
|
||||
parent-id
|
||||
to-index
|
||||
ids
|
||||
:ignore-parents? ignore-parents?))
|
||||
undo-id (js/Symbol)]
|
||||
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
|
|
|
@ -232,7 +232,8 @@
|
|||
ids (->> ids
|
||||
(remove #(ctn/has-any-copy-parent? objects (get objects %)))
|
||||
;; components can't be ungrouped
|
||||
(remove #(ctk/instance-head? (get objects %))))
|
||||
(remove #(ctk/instance-head? (get objects %)))
|
||||
(remove #(ctk/is-variant-container? (get objects %))))
|
||||
|
||||
changes-list (sequence (keep prepare) ids)
|
||||
|
||||
|
|
|
@ -930,14 +930,17 @@
|
|||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state page-id)
|
||||
data (dsh/lookup-file-data state)
|
||||
ids (cleanup-invalid-moving-shapes ids objects frame-id)
|
||||
changes (cls/generate-relocate (pcb/empty-changes it)
|
||||
objects
|
||||
frame-id
|
||||
page-id
|
||||
drop-index
|
||||
ids
|
||||
:cell cell)]
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-page-id page-id)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/with-library-data data)
|
||||
(cls/generate-relocate
|
||||
frame-id
|
||||
drop-index
|
||||
ids
|
||||
:cell cell))]
|
||||
|
||||
(when (and (some? frame-id) (d/not-empty? changes))
|
||||
(rx/of (dch/commit-changes changes)
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.logic.variants :as clv]
|
||||
[app.common.types.components-list :as ctcl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.changes :as dch]
|
||||
[app.main.data.helpers :as dsh]
|
||||
|
@ -22,11 +21,7 @@
|
|||
[beicon.v2.core :as rx]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(defn find-related-components
|
||||
[data objects variant-id]
|
||||
(->> (dm/get-in objects [variant-id :shapes])
|
||||
(map #(dm/get-in objects [% :component-id]))
|
||||
(map #(ctcl/get-component data % true))))
|
||||
(dm/export clv/find-related-components)
|
||||
|
||||
(defn update-property-name
|
||||
"Update the variant property name on the position pos
|
||||
|
@ -39,10 +34,11 @@
|
|||
data (dsh/lookup-file-data state)
|
||||
objects (-> (dsh/get-page data page-id)
|
||||
(get :objects))
|
||||
related-components (find-related-components data objects variant-id)
|
||||
|
||||
changes (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/with-library-data data)
|
||||
(clv/generate-update-property-name related-components pos new-name))
|
||||
(clv/generate-update-property-name variant-id pos new-name))
|
||||
undo-id (js/Symbol)]
|
||||
(rx/of
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
|
@ -59,17 +55,11 @@
|
|||
data (dsh/lookup-file-data state)
|
||||
objects (-> (dsh/get-page data page-id)
|
||||
(get :objects))
|
||||
component (ctcl/get-component data component-id true)
|
||||
main-id (:main-instance-id component)
|
||||
properties (-> (:variant-properties component)
|
||||
(update pos assoc :value value))
|
||||
|
||||
name (clv/properties-to-name properties)
|
||||
|
||||
changes (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/with-objects objects)
|
||||
(clv/generate-update-property-value component-id main-id pos value name))
|
||||
(clv/generate-update-property-value component-id pos value))
|
||||
undo-id (js/Symbol)]
|
||||
(rx/of
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
|
@ -88,12 +78,11 @@
|
|||
data (dsh/lookup-file-data state)
|
||||
objects (-> (dsh/get-page data page-id)
|
||||
(get :objects))
|
||||
related-components (find-related-components data objects variant-id)
|
||||
|
||||
changes (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/with-objects objects)
|
||||
(clv/generate-remove-property related-components pos))
|
||||
(clv/generate-remove-property variant-id pos))
|
||||
|
||||
undo-id (js/Symbol)]
|
||||
(rx/of
|
||||
|
@ -105,7 +94,7 @@
|
|||
|
||||
(defn add-new-property
|
||||
"Add a new variant property to all the components with this variant-id"
|
||||
[variant-id]
|
||||
[variant-id & [options]]
|
||||
(ptk/reify ::add-new-property
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
|
@ -114,20 +103,10 @@
|
|||
objects (-> (dsh/get-page data page-id)
|
||||
(get :objects))
|
||||
|
||||
related-components (find-related-components data objects variant-id)
|
||||
|
||||
|
||||
property-name (str "Property" (-> related-components
|
||||
first
|
||||
:variant-properties
|
||||
count
|
||||
inc))
|
||||
|
||||
changes (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-library-data data)
|
||||
(pcb/with-objects objects)
|
||||
(clv/generate-add-new-property related-components property-name))
|
||||
|
||||
(clv/generate-add-new-property variant-id options))
|
||||
|
||||
undo-id (js/Symbol)]
|
||||
(rx/of
|
||||
|
@ -155,7 +134,7 @@
|
|||
(defn transform-in-variant
|
||||
"Given the id of a main shape of a component, creates a variant structure for
|
||||
that component"
|
||||
[id]
|
||||
[main-instance-id]
|
||||
(ptk/reify ::transform-in-variant
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -165,7 +144,7 @@
|
|||
file-id (:current-file-id state)
|
||||
page-id (:current-page-id state)
|
||||
objects (dsh/lookup-page-objects state file-id page-id)
|
||||
main (get objects id)
|
||||
main (get objects main-instance-id)
|
||||
main-id (:id main)
|
||||
undo-id (js/Symbol)]
|
||||
|
||||
|
@ -193,5 +172,5 @@
|
|||
(dwl/duplicate-component file-id (:component-id main) new-component-id)
|
||||
(set-variant-id (:component-id main) variant-id)
|
||||
(set-variant-id new-component-id variant-id)
|
||||
(add-new-property variant-id)
|
||||
(add-new-property variant-id {:fill-values? true})
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
|
|
@ -324,8 +324,8 @@
|
|||
any-in-copy? (some true? (map #(ctn/has-any-copy-parent? objects %) shapes))
|
||||
|
||||
;; components can't be ungrouped
|
||||
has-frame? (->> shapes (d/seek #(and (cfh/frame-shape? %) (not (ctk/instance-head? %)))))
|
||||
has-group? (->> shapes (d/seek #(and (cfh/group-shape? %) (not (ctk/instance-head? %)))))
|
||||
has-frame? (->> shapes (d/seek #(and (cfh/frame-shape? %) (not (ctk/instance-head? %)) (not (ctk/is-variant-container? %)))))
|
||||
has-group? (->> shapes (d/seek #(and (cfh/group-shape? %) (not (ctk/instance-head? %)) (not (ctk/is-variant-container? %)))))
|
||||
has-bool? (->> shapes (d/seek cfh/bool-shape?))
|
||||
has-mask? (->> shapes (d/seek :masked-group))
|
||||
|
||||
|
|
|
@ -254,11 +254,11 @@
|
|||
(mf/deps related-components)
|
||||
(fn [prop-name]
|
||||
(->> related-components
|
||||
(mapcat (fn [item]
|
||||
(map :value (filter (fn [prop] (= (:name prop) prop-name))
|
||||
(:variant-properties item)))))
|
||||
(filter some?)
|
||||
(mapcat (fn [component]
|
||||
(map :value (filter #(= (:name %) prop-name)
|
||||
(:variant-properties component)))))
|
||||
distinct
|
||||
(map #(if (str/empty? %) "--" %))
|
||||
(map (fn [val] {:label val :id val})))))
|
||||
|
||||
filter-matching
|
||||
|
@ -278,8 +278,7 @@
|
|||
(mf/use-fn
|
||||
(mf/deps id-component)
|
||||
(fn [pos value]
|
||||
(when-not (str/empty? value)
|
||||
(st/emit! (dwv/update-property-value id-component pos value)))))
|
||||
(st/emit! (dwv/update-property-value id-component pos value))))
|
||||
|
||||
switch-component
|
||||
(mf/use-fn
|
||||
|
@ -293,7 +292,7 @@
|
|||
(if (ctk/main-instance? shape)
|
||||
[:*
|
||||
[:span {:class (stl/css :variant-property-name :variant-property-name-bg)} (:name prop)]
|
||||
[:> combobox* {:default-selected (str (or (:value prop) ""))
|
||||
[:> combobox* {:default-selected (if (str/empty? (:value prop)) "--" (:value prop))
|
||||
:options (clj->js (get-options (:name prop)))
|
||||
:on-change (partial change-property-value pos)}]]
|
||||
|
||||
|
@ -761,7 +760,10 @@
|
|||
properties (->> (dwv/find-related-components data objects variant-id)
|
||||
(mapcat :variant-properties)
|
||||
(group-by :name)
|
||||
(map (fn [[k v]] {:name k :values (map :value v)})))
|
||||
(map (fn [[k v]]
|
||||
{:name k
|
||||
:values (distinct
|
||||
(map #(if (str/empty? (:value %)) "--" (:value %)) v))})))
|
||||
|
||||
menu-open* (mf/use-state false)
|
||||
menu-open? (deref menu-open*)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue