diff --git a/frontend/src/arthur/events/project.cljs b/frontend/src/arthur/events/project.cljs index 6838371..ea84edb 100644 --- a/frontend/src/arthur/events/project.cljs +++ b/frontend/src/arthur/events/project.cljs @@ -703,6 +703,24 @@ (-> (edit/edit db #(assoc-in % [:palettes id] p)) (assoc-in [:ui :palette] id))))) +(rf/reg-event-db + ::duplicate-palette + ;; A copy of an existing palette, selected so the next colour edit lands on the + ;; copy rather than the original. The point is a variant: start from a palette + ;; that works and change two tones, instead of 16 colour pickers from black. + ;; `pal/palettes` is the source so the implicit default - a project that has + ;; never had a palette asset of its own - can be duplicated like any other. + (fn [db [_ id]] + (let [clip (:clip (store/entry (:clip/current db))) + p (get (pal/palettes clip) id)] + (if-not p + db + (let [new-id (random-uuid)] + (-> (edit/edit db #(assoc-in % [:palettes new-id] + (assoc p :id new-id + :name (str (:name p) " copy")))) + (assoc-in [:ui :palette] new-id))))))) + (rf/reg-event-db ::palette-name (fn [db [_ id value]] diff --git a/frontend/src/arthur/ui/palette.cljs b/frontend/src/arthur/ui/palette.cljs index 444887c..6559d5b 100644 --- a/frontend/src/arthur/ui/palette.cljs +++ b/frontend/src/arthur/ui/palette.cljs @@ -64,6 +64,8 @@ (for [[id p] (sort-by (comp str :name val) (pal/palettes clip))] ^{:key (str id)} [:option {:value (str id)} (:name p)])] [:button {:title "new 16-slot palette" :on-click #(rf/dispatch [::project/new-palette])} "+"] + [:button {:title (str "duplicate " (:name palette) " — a copy you can retone") + :on-click #(rf/dispatch [::project/duplicate-palette pid])} "⧉"] [:div.swatches (doall (map-indexed #(swatch pid %1 %2 tone placements) (:slots palette)))] [:span.dim (str tone)] (when (> (count selections) 1)