From 09b74de1622de9239a1c9995e803a7f3be1cd267 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 3 Oct 2026 03:51:17 -0400 Subject: [PATCH] Duplicate a palette from the palette bar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Making a variant meant 16 colour pickers from black: the only button was "+", which seeds an untitled palette from the built-in defaults. The copy is selected on creation, so the next colour edit lands on it rather than on the palette it came from. `pal/palettes` is the source, so the implicit default — a project that has never had a palette asset of its own — duplicates like any other. Co-Authored-By: Claude Opus 5 --- frontend/src/arthur/events/project.cljs | 18 ++++++++++++++++++ frontend/src/arthur/ui/palette.cljs | 2 ++ 2 files changed, 20 insertions(+) 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)