From 66444e27b19d8f51d385101d9186b2f8c4007a4f Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Mar 2023 11:30:46 +0200 Subject: [PATCH 1/5] :bug: Fix problem with selection colors and texts --- CHANGES.md | 1 + .../options/menus/color_selection.cljs | 50 ++++++++++++------- .../sidebar/options/rows/color_row.cljs | 3 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cd5fbe92e..10d5063dc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -64,6 +64,7 @@ - Fix dashboard left sidebar, the [x] overlaps the field [Taiga #5064](https://tree.taiga.io/project/penpot/issue/5064) - Fix expanded typography on assets sidebar is moving [Taiga #5063](https://tree.taiga.io/project/penpot/issue/5063) - Fix spelling mistake in confirmation after importing only 1 file [Taiga #5095](https://tree.taiga.io/project/penpot/issue/5095) +- Fix problem with selection colors and texts [Taiga #5079](https://tree.taiga.io/project/penpot/issue/5079) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/color_selection.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/color_selection.cljs index 7a18745e8..857e60da5 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/color_selection.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/color_selection.cljs @@ -161,27 +161,37 @@ on-change (mf/use-fn - (fn [new-color old-color] + (fn [new-color old-color from-picker?] (let [old-color (-> old-color (dissoc :name) (dissoc :path) (d/without-nils)) - prev-color (-> @prev-color* - (dissoc :name) - (dissoc :path) - (d/without-nils)) + prev-color (when @prev-color* + (-> @prev-color* + (dissoc :name) + (dissoc :path) + (d/without-nils))) ;; When dragging on the color picker sometimes all the shapes hasn't updated the color to the prev value so we need this extra calculation shapes-by-old-color (get @grouped-colors* old-color) shapes-by-prev-color (get @grouped-colors* prev-color) shapes-by-color (or shapes-by-prev-color shapes-by-old-color)] - (reset! prev-color* new-color) - (st/emit! (dc/change-color-in-selected new-color shapes-by-color old-color))))) - on-open (mf/use-fn - (fn [color] - (reset! prev-color* color))) + (when from-picker? + (reset! prev-color* new-color)) + + (st/emit! (dc/change-color-in-selected new-color shapes-by-color (or prev-color old-color)))))) + + on-open + (mf/use-fn + (fn [] + (reset! prev-color* nil))) + + on-close + (mf/use-fn + (fn [] + (reset! prev-color* nil))) on-detach (mf/use-fn @@ -212,8 +222,9 @@ :index index :on-detach on-detach :select-only select-only - :on-change #(on-change % color) - :on-open on-open}]) + :on-change #(on-change %1 color %2) + :on-open on-open + :on-close on-close}]) (when (and (false? @expand-lib-color) (< 3 (count library-colors))) [:div.expand-colors {:on-click #(reset! expand-lib-color true)} [:span i/actions] @@ -225,8 +236,9 @@ :index index :on-detach on-detach :select-only select-only - :on-change #(on-change % color) - :on-open on-open}]))] + :on-change #(on-change %1 color %2) + :on-open on-open + :on-close on-close}]))] [:div.selected-colors (for [[index color] (d/enumerate (take 3 colors))] @@ -234,8 +246,9 @@ :color color :index index :select-only select-only - :on-change #(on-change % color) - :on-open on-open}]) + :on-change #(on-change %1 color %2) + :on-open on-open + :on-close on-close}]) (when (and (false? @expand-color) (< 3 (count colors))) [:div.expand-colors {:on-click #(reset! expand-color true)} [:span i/actions] @@ -246,5 +259,6 @@ :color color :index index :select-only select-only - :on-change #(on-change % color) - :on-open on-open}]))]]]))) + :on-change #(on-change %1 color %2) + :on-open on-open + :on-close on-close}]))]]]))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/rows/color_row.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/rows/color_row.cljs index 5a0d42059..4a5653216 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/rows/color_row.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/rows/color_row.cljs @@ -113,7 +113,8 @@ :y y :disable-gradient disable-gradient :disable-opacity disable-opacity - :on-change #(on-change (merge uc/empty-color %)) + ;; on-change second parameter means if the source is the color-picker + :on-change #(on-change (merge uc/empty-color %) true) :on-close (fn [value opacity id file-id] (when on-close (on-close value opacity id file-id))) From ac23c7bb4ad59bf40b500c8f1453c1f90e7658e4 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Mar 2023 12:18:24 +0200 Subject: [PATCH 2/5] :bug: Remove "show in view mode" flag when moving frame to frame --- CHANGES.md | 1 + frontend/src/app/main/data/workspace.cljs | 3 +++ frontend/src/app/main/data/workspace/shapes.cljs | 1 + frontend/src/app/main/data/workspace/transforms.cljs | 7 +++++-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 10d5063dc..aa22feb71 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -65,6 +65,7 @@ - Fix expanded typography on assets sidebar is moving [Taiga #5063](https://tree.taiga.io/project/penpot/issue/5063) - Fix spelling mistake in confirmation after importing only 1 file [Taiga #5095](https://tree.taiga.io/project/penpot/issue/5095) - Fix problem with selection colors and texts [Taiga #5079](https://tree.taiga.io/project/penpot/issue/5079) +- Remove "show in view mode" flag when moving frame to frame [Taiga #5091](https://tree.taiga.io/project/penpot/issue/5091) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index a24dd1c30..05c1d8cb3 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -663,6 +663,9 @@ (cond-> (not (ctl/any-layout? objects parent-id)) (pcb/update-shapes ordered-indexes ctl/remove-layout-item-data)) + ;; Remove the hide in viewer flag + (pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true))) + ;; Move the shapes (pcb/change-parent parent-id shapes diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 525fc5397..ea0f38a09 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -137,6 +137,7 @@ (pcb/with-objects objects) (cond-> (not (ctl/any-layout? objects frame-id)) (pcb/update-shapes ordered-indexes ctl/remove-layout-item-data)) + (pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true))) (pcb/change-parent frame-id to-move-shapes 0) (cond-> (ctl/grid-layout? objects frame-id) (pcb/update-shapes [frame-id] ctl/assign-cells))))] diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 8c4a297b5..be254bb69 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -104,7 +104,7 @@ (defn start-resize "Enter mouse resize mode, until mouse button is released." [handler ids shape] - (letfn [(resize + (letfn [(resize [shape initial layout [point lock? center? point-snap]] (let [{:keys [width height]} (:selrect shape) {:keys [rotation]} shape @@ -745,13 +745,16 @@ (remove (fn [shape] (and (ctl/layout-absolute? shape) (= frame-id (:parent-id shape)))))) + moving-shapes-ids + (map :id moving-shapes) changes (-> (pcb/empty-changes it page-id) (pcb/with-objects objects) ;; Remove layout-item properties when moving a shape outside a layout (cond-> (not (ctl/any-layout? objects frame-id)) - (pcb/update-shapes (map :id moving-shapes) ctl/remove-layout-item-data)) + (pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data)) + (pcb/update-shapes moving-shapes-ids #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true))) (pcb/change-parent frame-id moving-shapes drop-index) (pcb/remove-objects empty-parents))] From d54e152a3db4b45c65563a86cd06fb4760b94d15 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Mar 2023 15:14:23 +0200 Subject: [PATCH 3/5] :bug: Fix problem creating files in project page --- CHANGES.md | 1 + frontend/src/app/main/ui/dashboard/files.cljs | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index aa22feb71..3ecb1cdb7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -66,6 +66,7 @@ - Fix spelling mistake in confirmation after importing only 1 file [Taiga #5095](https://tree.taiga.io/project/penpot/issue/5095) - Fix problem with selection colors and texts [Taiga #5079](https://tree.taiga.io/project/penpot/issue/5079) - Remove "show in view mode" flag when moving frame to frame [Taiga #5091](https://tree.taiga.io/project/penpot/issue/5091) +- Fix problem creating files in project page [Taiga #5060](https://tree.taiga.io/project/penpot/issue/5060) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/frontend/src/app/main/ui/dashboard/files.cljs b/frontend/src/app/main/ui/dashboard/files.cljs index fb7dc0936..e67ebbfc6 100644 --- a/frontend/src/app/main/ui/dashboard/files.cljs +++ b/frontend/src/app/main/ui/dashboard/files.cljs @@ -144,6 +144,7 @@ create-file (mf/use-fn + (mf/deps project) (fn [origin] (st/emit! (with-meta (dd/create-file {:project-id (:id project)}) {::ev/origin origin}))))] From 43fe2390c8a6facf9c646b1c8ff527bec873539b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Mar 2023 17:18:56 +0200 Subject: [PATCH 4/5] :bug: Fix problem with copy/paste shapes --- common/src/app/common/pages/helpers.cljc | 22 ++++++++++++++++++ frontend/src/app/main/data/workspace.cljs | 27 ++++++++--------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 589d2249b..a4748ba7f 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -595,3 +595,25 @@ (d/enumerate) (sort comparator-layout-z-index) (mapv second))) + +(defn common-parent-frame + "Search for the common frame for the selected shapes. Otherwise returns the root frame" + [objects selected] + + (loop [frame-id (get-in objects [(first selected) :frame-id]) + frame-parents (get-parent-ids objects frame-id) + selected (rest selected)] + (if (empty? selected) + frame-id + + (let [current (first selected) + parent? (into #{} (get-parent-ids objects current)) + + [frame-id frame-parents] + (if (parent? frame-id) + [frame-id frame-parents] + + (let [frame-id (d/seek parent? frame-parents)] + [frame-id (get-parent-ids objects frame-id)]))] + + (recur frame-id frame-parents (rest selected)))))) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 05c1d8cb3..ec0f3db00 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1304,8 +1304,8 @@ ;; Prepare the shape object. Mainly needed for image shapes ;; for retrieve the image data and convert it to the ;; data-url. - (prepare-object [objects selected+children {:keys [type] :as obj}] - (let [obj (maybe-translate obj objects selected+children)] + (prepare-object [objects parent-frame-id {:keys [type] :as obj}] + (let [obj (maybe-translate obj objects parent-frame-id)] (if (= type :image) (let [url (cf/resolve-file-media (:metadata obj))] (->> (http/send! {:method :get @@ -1328,20 +1328,11 @@ (update res :images conj img-part)) res))) - (maybe-translate [shape objects selected+children] - (let [frame-id (:frame-id shape) - root-frame-id (cph/get-shape-id-root-frame objects (:id shape))] - (cond - (cph/root-frame? shape) shape - (contains? selected+children root-frame-id) shape - - (cph/frame-shape? shape) - (let [frame (get objects root-frame-id)] - (gsh/translate-to-frame shape frame)) - - :else - (let [frame (get objects frame-id)] - (gsh/translate-to-frame shape frame))))) + (maybe-translate [shape objects parent-frame-id] + (if (= parent-frame-id uuid/zero) + shape + (let [frame (get objects parent-frame-id)] + (gsh/translate-to-frame shape frame)))) (on-copy-error [error] (js/console.error "Clipboard blocked:" error) @@ -1354,7 +1345,7 @@ selected (->> (wsh/lookup-selected state) (cph/clean-loops objects)) - selected+children (cph/selected-with-children objects selected) + parent-frame-id (cph/common-parent-frame objects selected) pdata (reduce (partial collect-object-ids objects) {} selected) initial {:type :copied-shapes :file-id (:current-file-id state) @@ -1369,7 +1360,7 @@ (catch :default e (on-copy-error e))) (->> (rx/from (seq (vals pdata))) - (rx/merge-map (partial prepare-object objects selected+children)) + (rx/merge-map (partial prepare-object objects parent-frame-id)) (rx/reduce collect-data initial) (rx/map (partial sort-selected state)) (rx/map t/encode-str) From a98ae69a03eed00d1456e1039fe3b13e38694a8c Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Mar 2023 17:41:51 +0200 Subject: [PATCH 5/5] :bug: Disable empty names on rename files --- CHANGES.md | 1 + frontend/src/app/main/ui/dashboard/grid.cljs | 4 +++- frontend/src/app/main/ui/dashboard/import.cljs | 9 ++++++--- frontend/src/app/main/ui/workspace/header.cljs | 11 +++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3ecb1cdb7..594c60481 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -67,6 +67,7 @@ - Fix problem with selection colors and texts [Taiga #5079](https://tree.taiga.io/project/penpot/issue/5079) - Remove "show in view mode" flag when moving frame to frame [Taiga #5091](https://tree.taiga.io/project/penpot/issue/5091) - Fix problem creating files in project page [Taiga #5060](https://tree.taiga.io/project/penpot/issue/5060) +- Disable empty names on rename files [Taiga #5088](https://tree.taiga.io/project/penpot/issue/5088) ### :heart: Community contributions by (Thank you!) - To @ondrejkonec: for contributing to the code with: diff --git a/frontend/src/app/main/ui/dashboard/grid.cljs b/frontend/src/app/main/ui/dashboard/grid.cljs index eba451495..c0d4b1c0a 100644 --- a/frontend/src/app/main/ui/dashboard/grid.cljs +++ b/frontend/src/app/main/ui/dashboard/grid.cljs @@ -268,7 +268,9 @@ (mf/use-fn (mf/deps file) (fn [name] - (st/emit! (dd/rename-file (assoc file :name name))) + (let [name (str/trim name)] + (when (not= name "") + (st/emit! (dd/rename-file (assoc file :name name))))) (swap! local assoc :edition false))) on-edit diff --git a/frontend/src/app/main/ui/dashboard/import.cljs b/frontend/src/app/main/ui/dashboard/import.cljs index 7bc0966ca..1aa8fbc73 100644 --- a/frontend/src/app/main/ui/dashboard/import.cljs +++ b/frontend/src/app/main/ui/dashboard/import.cljs @@ -22,6 +22,7 @@ [app.util.keyboard :as kbd] [app.util.webapi :as wapi] [beicon.core :as rx] + [cuerdas.core :as str] [potok.core :as ptk] [rumext.v2 :as mf])) @@ -61,9 +62,11 @@ (->> files (mapv (fn [file] - (cond-> file - (= (:file-id file) file-id) - (assoc :name new-name)))))) + (let [new-name (str/trim new-name)] + (cond-> file + (and (= (:file-id file) file-id) + (not= "" new-name)) + (assoc :name new-name))))))) (defn remove-file [files file-id] (->> files diff --git a/frontend/src/app/main/ui/workspace/header.cljs b/frontend/src/app/main/ui/workspace/header.cljs index 1ccd70f2a..7be23d60d 100644 --- a/frontend/src/app/main/ui/workspace/header.cljs +++ b/frontend/src/app/main/ui/workspace/header.cljs @@ -33,6 +33,7 @@ [app.util.keyboard :as kbd] [app.util.router :as rt] [beicon.core :as rx] + [cuerdas.core :as str] [okulary.core :as l] [potok.core :as ptk] [rumext.v2 :as mf])) @@ -150,10 +151,12 @@ :on-accept #(st/emit! (dwl/set-file-shared (:id file) false)) :count-libraries 1})))) - handle-blur (fn [_] - (let [value (-> edit-input-ref mf/ref-val dom/get-value)] - (st/emit! (dw/rename-file (:id file) value))) - (reset! editing? false)) + handle-blur + (fn [_] + (let [value (str/trim (-> edit-input-ref mf/ref-val dom/get-value))] + (when (not= value "") + (st/emit! (dw/rename-file (:id file) value)))) + (reset! editing? false)) handle-name-keydown (fn [event] (when (kbd/enter? event)