From 6d0b36e9b94333536adf7b8359c4f175298f7677 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 26 May 2021 10:41:12 +0200 Subject: [PATCH 1/9] :bug: Fix problem with new nodes in paths --- CHANGES.md | 1 + frontend/src/app/util/path/tools.cljs | 32 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3a0659912..d010a459d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -36,6 +36,7 @@ - Fix issue when group creation leaves an empty group [#1724](https://tree.taiga.io/project/penpot/issue/1724) - Fix problem with :multiple for colors and typographies [#1668](https://tree.taiga.io/project/penpot/issue/1668) - Fix problem with locked shapes when change parents [#974](https://github.com/penpot/penpot/issues/974) +- Fix problem with new nodes in paths [#978](https://github.com/penpot/penpot/issues/978) ### :arrow_up: Deps updates diff --git a/frontend/src/app/util/path/tools.cljs b/frontend/src/app/util/path/tools.cljs index c352196b5..4f0110786 100644 --- a/frontend/src/app/util/path/tools.cljs +++ b/frontend/src/app/util/path/tools.cljs @@ -164,11 +164,12 @@ [content points] (let [point-set (set points)] - (loop [segments [] - prev-point nil + (loop [segments [] + prev-point nil start-point nil - cur-cmd (first content) - content (rest content)] + index 0 + cur-cmd (first content) + content (rest content)] (let [;; Close-path makes a segment from the last point to the initial path point cur-point (if (= :close-path (:command cur-cmd)) @@ -191,12 +192,16 @@ segments (cond-> segments is-segment? - (conj [prev-point cur-point cur-cmd]))] + (conj {:start prev-point + :end cur-point + :cmd cur-cmd + :index index}))] (if (some? cur-cmd) (recur segments cur-point start-point + (inc index) (first content) (rest content)) @@ -205,12 +210,13 @@ (defn split-segments "Given a content creates splits commands between points with new segments" [content points value] + (let [split-command - (fn [[start end cmd]] + (fn [{:keys [start end cmd index]}] (case (:command cmd) - :line-to [cmd (upg/split-line-to start cmd value)] - :curve-to [cmd (upg/split-curve-to start cmd value)] - :close-path [cmd [(upc/make-line-to (gpt/line-val start end value)) cmd]] + :line-to [index (upg/split-line-to start cmd value)] + :curve-to [index (upg/split-curve-to start cmd value)] + :close-path [index [(upc/make-line-to (gpt/line-val start end value)) cmd]] nil)) cmd-changes @@ -219,12 +225,12 @@ (filter (comp not nil?))))) process-segments - (fn [command] - (if (contains? cmd-changes command) - (get cmd-changes command) + (fn [[index command]] + (if (contains? cmd-changes index) + (get cmd-changes index) [command]))] - (into [] (mapcat process-segments) content))) + (into [] (mapcat process-segments) (d/enumerate content)))) (defn remove-nodes "Removes from content the points given. Will try to reconstruct the paths From 67cd87728180665eada6575e373f7af737d3349c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 26 May 2021 11:54:40 +0200 Subject: [PATCH 2/9] :bug: Fix unexpected excetion related to rounding integers. --- common/app/common/math.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/app/common/math.cljc b/common/app/common/math.cljc index c81db2a39..22ebd97af 100644 --- a/common/app/common/math.cljc +++ b/common/app/common/math.cljc @@ -96,7 +96,7 @@ the nearest integer." [v] #?(:cljs (js/Math.round v) - :clj (Math/round v))) + :clj (Math/round (float v)))) (defn ceil "Returns the smallest integer greater than From 28348503370008dfce756307cfed775a500bdc72 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 26 May 2021 12:14:02 +0200 Subject: [PATCH 3/9] :paperclip: Add safety check on reg-objects change impl. --- common/app/common/pages/changes.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/app/common/pages/changes.cljc b/common/app/common/pages/changes.cljc index 0a792233c..4fa3f8b75 100644 --- a/common/app/common/pages/changes.cljc +++ b/common/app/common/pages/changes.cljc @@ -142,7 +142,7 @@ (defmethod process-change :reg-objects [data {:keys [page-id component-id shapes]}] (letfn [(reg-objects [objects] - (reduce #(update %1 %2 update-group %1) objects + (reduce #(d/update-when %1 %2 update-group %1) objects (sequence (comp (mapcat #(cons % (cph/get-parents % objects))) (map #(get objects %)) From 897f41bc7a776a952f323f69eaa2a9f4eb3e7e82 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 26 May 2021 12:39:41 +0200 Subject: [PATCH 4/9] :sparkles: Fix custom fonts embbedding issue. --- frontend/src/app/main/ui/shapes/text/embed.cljs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/shapes/text/embed.cljs b/frontend/src/app/main/ui/shapes/text/embed.cljs index 61ef3fd4e..dde62afd5 100644 --- a/frontend/src/app/main/ui/shapes/text/embed.cljs +++ b/frontend/src/app/main/ui/shapes/text/embed.cljs @@ -61,7 +61,8 @@ (defn get-font-css "Given a font and the variant-id, retrieves the style CSS for it." [{:keys [id backend family variants] :as font} font-variant-id] - (if (= :google backend) + (cond + (= :google backend) (let [uri (fonts/generate-gfonts-url {:family family :variants [{:id font-variant-id}]})] (->> (http/send! {:method :get :mode :cors @@ -70,6 +71,14 @@ :response-type :text}) (rx/map :body) (http/as-promise))) + + + (= :custom backend) + (let [variant (d/seek #(= (:id %) font-variant-id) variants) + result (fonts/generate-custom-font-variant-css family variant)] + (p/resolved result)) + + :else (let [{:keys [name weight style suffix] :as variant} (d/seek #(= (:id %) font-variant-id) variants) result (str/fmt font-face-template {:family family :style style From ba211e3cbd902f6e1f6b1f77f86325a2b564bf31 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 26 May 2021 13:31:07 +0200 Subject: [PATCH 5/9] :bug: Fix wrong type usage on libraries changes. --- .../app/main/data/workspace/libraries.cljs | 122 +++++++++--------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 5e076b766..e7adae704 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -414,22 +414,22 @@ (get component :objects) update-new-shape) - rchanges (map (fn [obj] - {:type :add-obj - :id (:id obj) - :page-id page-id - :frame-id (:frame-id obj) - :parent-id (:parent-id obj) - :ignore-touched true - :obj obj}) - new-shapes) + rchanges (mapv (fn [obj] + {:type :add-obj + :id (:id obj) + :page-id page-id + :frame-id (:frame-id obj) + :parent-id (:parent-id obj) + :ignore-touched true + :obj obj}) + new-shapes) - uchanges (map (fn [obj] - {:type :del-obj - :id (:id obj) - :page-id page-id - :ignore-touched true}) - new-shapes)] + uchanges (mapv (fn [obj] + {:type :del-obj + :id (:id obj) + :page-id page-id + :ignore-touched true}) + new-shapes)] (rx/of (dch/commit-changes {:redo-changes rchanges :undo-changes uchanges @@ -448,53 +448,53 @@ objects (wsh/lookup-page-objects state page-id) shapes (cp/get-object-with-children id objects) - rchanges (map (fn [obj] - {:type :mod-obj - :page-id page-id - :id (:id obj) - :operations [{:type :set - :attr :component-id - :val nil} - {:type :set - :attr :component-file - :val nil} - {:type :set - :attr :component-root? - :val nil} - {:type :set - :attr :remote-synced? - :val nil} - {:type :set - :attr :shape-ref - :val nil} - {:type :set - :attr :touched - :val nil}]}) - shapes) + rchanges (mapv (fn [obj] + {:type :mod-obj + :page-id page-id + :id (:id obj) + :operations [{:type :set + :attr :component-id + :val nil} + {:type :set + :attr :component-file + :val nil} + {:type :set + :attr :component-root? + :val nil} + {:type :set + :attr :remote-synced? + :val nil} + {:type :set + :attr :shape-ref + :val nil} + {:type :set + :attr :touched + :val nil}]}) + shapes) - uchanges (map (fn [obj] - {:type :mod-obj - :page-id page-id - :id (:id obj) - :operations [{:type :set - :attr :component-id - :val (:component-id obj)} - {:type :set - :attr :component-file - :val (:component-file obj)} - {:type :set - :attr :component-root? - :val (:component-root? obj)} - {:type :set - :attr :remote-synced? - :val (:remote-synced? obj)} - {:type :set - :attr :shape-ref - :val (:shape-ref obj)} - {:type :set - :attr :touched - :val (:touched obj)}]}) - shapes)] + uchanges (mapv (fn [obj] + {:type :mod-obj + :page-id page-id + :id (:id obj) + :operations [{:type :set + :attr :component-id + :val (:component-id obj)} + {:type :set + :attr :component-file + :val (:component-file obj)} + {:type :set + :attr :component-root? + :val (:component-root? obj)} + {:type :set + :attr :remote-synced? + :val (:remote-synced? obj)} + {:type :set + :attr :shape-ref + :val (:shape-ref obj)} + {:type :set + :attr :touched + :val (:touched obj)}]}) + shapes)] (rx/of (dch/commit-changes {:redo-changes rchanges :undo-changes uchanges From 52f699c175fe10b75ce5cfecd212ed382430bbfe Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 26 May 2021 13:25:07 +0200 Subject: [PATCH 6/9] :bug: Fix problems with mov-objects --- common/app/common/pages/changes.cljc | 35 +++++++++++++++------------- common/app/common/pages/helpers.cljc | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/common/app/common/pages/changes.cljc b/common/app/common/pages/changes.cljc index 4fa3f8b75..5d2624574 100644 --- a/common/app/common/pages/changes.cljc +++ b/common/app/common/pages/changes.cljc @@ -221,28 +221,31 @@ ;; the new destination target parent id. (if (= prev-parent-id parent-id) objects - (loop [sid shape-id - pid prev-parent-id - objects objects] - (let [obj (get objects pid)] - (cond-> objects - true - (update-in [pid :shapes] strip-id sid) + (let [sid shape-id + pid prev-parent-id + obj (get objects pid) + component? (and (:shape-ref obj) + (= (:type obj) :group) + (not ignore-touched))] - (and (:shape-ref obj) - (= (:type obj) :group) - (not ignore-touched)) - (-> - (update-in [pid :touched] - cph/set-touched-group :shapes-group) - (d/dissoc-in [pid :remote-synced?])))))))) + (-> objects + (d/update-in-when [pid :shapes] strip-id sid) + + (cond-> component? + (d/update-when + pid + #(-> % + (update :touched cph/set-touched-group :shapes-group) + (dissoc :remote-synced?))))))))) (update-parent-id [objects id] - (assoc-in objects [id :parent-id] parent-id)) + (-> objects + (d/update-when id assoc :parent-id parent-id))) ;; Updates the frame-id references that might be outdated (assign-frame-id [frame-id objects id] - (let [objects (update objects id assoc :frame-id frame-id) + (let [objects (-> objects + (d/update-when id assoc :frame-id frame-id)) obj (get objects id)] (cond-> objects ;; If we moving frame, the parent frame is the root diff --git a/common/app/common/pages/helpers.cljc b/common/app/common/pages/helpers.cljc index 87299b2a3..9eb194c27 100644 --- a/common/app/common/pages/helpers.cljc +++ b/common/app/common/pages/helpers.cljc @@ -181,7 +181,7 @@ (defn calculate-invalid-targets [shape-id objects] (let [result #{shape-id} - children (get-in objects [shape-id :shape]) + children (get-in objects [shape-id :shapes]) reduce-fn (fn [result child-id] (into result (calculate-invalid-targets child-id objects)))] (reduce reduce-fn result children))) From 7a32d902ec11bb588c64b12f44c1f5ba50979bca Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 26 May 2021 14:33:55 +0200 Subject: [PATCH 7/9] :bug: Fix problem with moving shapes into frames --- frontend/src/app/main/data/workspace/transforms.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index e726917de..0e2c7f230 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -282,7 +282,8 @@ moving-shapes (->> ids (cp/clean-loops objects) (map #(get objects %)) - (remove #(= (:frame-id %) frame-id))) + (remove #(or (nil? %) + (= (:frame-id %) frame-id)))) rch [{:type :mov-objects :page-id page-id From 6710d99878cf8fbdb235671d4028c5203d1c439e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 26 May 2021 15:22:41 +0200 Subject: [PATCH 8/9] :bug: Fix dashboard ordering issue. --- frontend/src/app/main/data/workspace/changes.cljs | 1 - frontend/src/app/main/ui/dashboard/projects.cljs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/data/workspace/changes.cljs b/frontend/src/app/main/data/workspace/changes.cljs index b7be2c2eb..d9910e13a 100644 --- a/frontend/src/app/main/data/workspace/changes.cljs +++ b/frontend/src/app/main/data/workspace/changes.cljs @@ -115,7 +115,6 @@ [{:keys [redo-changes undo-changes origin save-undo? file-id] :or {save-undo? true}}] - (log/debug :msg "commit-changes" :js/redo-changes redo-changes :js/undo-changes undo-changes) diff --git a/frontend/src/app/main/ui/dashboard/projects.cljs b/frontend/src/app/main/ui/dashboard/projects.cljs index 911f6afc4..342d377f0 100644 --- a/frontend/src/app/main/ui/dashboard/projects.cljs +++ b/frontend/src/app/main/ui/dashboard/projects.cljs @@ -171,7 +171,8 @@ (for [{:keys [id] :as project} projects] (let [files (when recent-map (->> (vals recent-map) - (filterv #(= id (:project-id %)))))] + (filterv #(= id (:project-id %))) + (sort-by :modified-at #(compare %2 %1))))] [:& project-item {:project project :files files :first? (= project (first projects)) From 0de8bfeba60f7d644f33dbcb6fd1b70f817f0c6b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 26 May 2021 16:12:29 +0200 Subject: [PATCH 9/9] :bug: Fix problem when creating a component with empty data --- .../src/app/main/data/workspace/libraries.cljs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index e7adae704..50e29227e 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -264,13 +264,14 @@ objects (wsh/lookup-page-objects state page-id) selected (wsh/lookup-selected state) selected (cp/clean-loops objects selected)] - (let [[group rchanges uchanges] - (dwlh/generate-add-component selected objects page-id file-id)] - (when-not (empty? rchanges) - (rx/of (dch/commit-changes {:redo-changes rchanges - :undo-changes uchanges - :origin it}) - (dwc/select-shapes (d/ordered-set (:id group)))))))))) + (when-not (empty? selected) + (let [[group rchanges uchanges] + (dwlh/generate-add-component selected objects page-id file-id)] + (when-not (empty? rchanges) + (rx/of (dch/commit-changes {:redo-changes rchanges + :undo-changes uchanges + :origin it}) + (dwc/select-shapes (d/ordered-set (:id group))))))))))) (defn rename-component "Rename the component with the given id, in the current file library."