From 0392a1649f49e3000b4752eb063b747a6f198163 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 30 Mar 2022 12:27:30 +0200 Subject: [PATCH 01/19] :bug: Remove default fill-color and fill-opacity on image shapes --- common/src/app/common/pages/common.cljc | 2 +- common/src/app/common/pages/migrations.cljc | 23 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/pages/common.cljc b/common/src/app/common/pages/common.cljc index 43cd9371c..b66aa935f 100644 --- a/common/src/app/common/pages/common.cljc +++ b/common/src/app/common/pages/common.cljc @@ -9,7 +9,7 @@ [app.common.colors :as clr] [app.common.uuid :as uuid])) -(def file-version 13) +(def file-version 14) (def default-color clr/gray-20) (def root uuid/zero) diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index d87f2156e..5f0723250 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -12,7 +12,8 @@ [app.common.geom.shapes.path :as gsp] [app.common.math :as mth] [app.common.pages :as cp] - [app.common.uuid :as uuid])) + [app.common.uuid :as uuid] + [cuerdas.core :as str])) ;; TODO: revisit this and rename to file-migrations @@ -300,3 +301,23 @@ (update page :objects #(d/mapm update-object %)))] (update data :pages-index #(d/mapm update-page %)))) + +(defmethod migrate 14 + [data] + (letfn [(update-object [_ {:keys [type] :as object}] + (if (= :image type) + (let [fill-color (str/upper (:fill-color object)) + fill-opacity (:fill-opacity object)] + (cond-> object + (and (= 1 fill-opacity) + (or (= "#B1B2B5" fill-color) + (= "#7B7D85" fill-color))) + (dissoc :fill-color :fill-opacity))) + object)) + + (update-container [_ container] + (update container :objects #(d/mapm update-object %)))] + + (-> data + (update :pages-index #(d/mapm update-container %)) + (update :components #(d/mapm update-container %))))) From 586bd13cc204cf5246f6f6bb2bcfb4f4937afb68 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 30 Mar 2022 13:00:22 +0200 Subject: [PATCH 02/19] :bug: Fix issue with shift+select to deselect shapes --- CHANGES.md | 6 ++ common/src/app/common/data.cljc | 10 ++++ .../app/main/data/workspace/selection.cljs | 8 +-- .../app/main/data/workspace/transforms.cljs | 60 ++++++++++++------- .../main/ui/workspace/viewport/actions.cljs | 9 +-- 5 files changed, 56 insertions(+), 37 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9d4f1422d..d8f2b61f6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # CHANGELOG +## 1.12.3-beta + +### :bug: Bugs fixed + +- Fix issue with shift+select to deselect shapes [Taiga #3154](https://tree.taiga.io/project/penpot/issue/3154) + ## 1.12.2-beta ### :bug: Bugs fixed diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 69e30c6a5..953dd31ba 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -693,3 +693,13 @@ acc))) acc)))))) +(defn toggle-selection + ([set value] + (toggle-selection set value false)) + + ([set value toggle?] + (if-not toggle? + (conj (ordered-set) value) + (if (contains? set value) + (disj set value) + (conj set value))))) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 08ec41784..08f2985e5 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -117,13 +117,7 @@ (ptk/reify ::select-shape ptk/UpdateEvent (update [_ state] - (update-in state [:workspace-local :selected] - (fn [selected] - (if-not toggle? - (conj (d/ordered-set) id) - (if (contains? selected id) - (disj selected id) - (conj selected id)))))) + (update-in state [:workspace-local :selected] d/toggle-selection id toggle?)) ptk/WatchEvent (watch [_ state _] diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index ddc4f5686..8f5d3cc85 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -484,30 +484,44 @@ (defn start-move-selected "Enter mouse move mode, until mouse button is released." - [] - (ptk/reify ::start-move-selected - ptk/WatchEvent - (watch [_ state stream] - (let [initial (deref ms/mouse-position) - selected (wsh/lookup-selected state {:omit-blocked? true}) - stopper (rx/filter ms/mouse-up? stream)] - (when-not (empty? selected) - (->> ms/mouse-position - (rx/map #(gpt/to-vec initial %)) - (rx/map #(gpt/length %)) - (rx/filter #(> % 1)) - (rx/take 1) - (rx/with-latest vector ms/mouse-position-alt) - (rx/mapcat - (fn [[_ alt?]] - (if alt? - ;; When alt is down we start a duplicate+move - (rx/of (start-move-duplicate initial) - (dws/duplicate-selected false)) - ;; Otherwise just plain old move - (rx/of (start-move initial selected))))) - (rx/take-until stopper))))))) + ([] + (start-move-selected nil false)) + ([id shift?] + (ptk/reify ::start-move-selected + ptk/WatchEvent + (watch [_ state stream] + (let [initial (deref ms/mouse-position) + + ;; We toggle the selection so we don't have to wait for the event + selected + (cond-> (wsh/lookup-selected state {:omit-blocked? true}) + (some? id) + (d/toggle-selection id shift?)) + + stopper (rx/filter ms/mouse-up? stream)] + (when (or (d/not-empty? selected) (some? id)) + (->> ms/mouse-position + (rx/map #(gpt/to-vec initial %)) + (rx/map #(gpt/length %)) + (rx/filter #(> % 1)) + (rx/take 1) + (rx/with-latest vector ms/mouse-position-alt) + (rx/mapcat + (fn [[_ alt?]] + (rx/concat + (if (some? id) + (rx/of (dws/select-shape id shift?)) + (rx/empty)) + + (if alt? + ;; When alt is down we start a duplicate+move + (rx/of (start-move-duplicate initial) + (dws/duplicate-selected false)) + + ;; Otherwise just plain old move + (rx/of (start-move initial selected)))))) + (rx/take-until stopper)))))))) (defn- start-move-duplicate [from-position] diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index cc2a2c5b4..bb273a51a 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -94,9 +94,7 @@ (st/emit! (dw/handle-area-selection shift? ctrl?)) (not drawing-tool) - (st/emit! (when (or shift? (not selected?)) - (dw/select-shape id shift?)) - (dw/start-move-selected))))))))))) + (st/emit! (dw/start-move-selected id shift?))))))))))) (defn on-move-selected [hover hover-ids selected space?] @@ -153,16 +151,13 @@ (let [ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) alt? (kbd/alt? event) - hovering? (some? @hover) - frame? (= :frame (:type @hover)) - selected? (contains? selected (:id @hover))] + frame? (= :frame (:type @hover))] (st/emit! (ms/->MouseEvent :click ctrl? shift? alt?)) (when (and hovering? (or (not frame?) ctrl?) (not @space?) - (not selected?) (not edition) (not drawing-path?) (not drawing-tool)) From f0d956f71cd1b50bb2425b10387ec955d993c3d9 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 30 Mar 2022 13:43:46 +0200 Subject: [PATCH 03/19] :paperclip: Update version.txt file --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 47c06a59c..6907484ac 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.12.2-beta +1.12.3-beta From 4c6433b0f18d7fa3f90e3611d744337f5e161808 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 30 Mar 2022 14:38:36 +0200 Subject: [PATCH 04/19] :sparkles: Improve migration 14 Remove frame thumbnail if the migration modifies a shape. --- common/src/app/common/pages/migrations.cljc | 33 +++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index 5f0723250..e7a26ad8e 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -304,19 +304,28 @@ (defmethod migrate 14 [data] - (letfn [(update-object [_ {:keys [type] :as object}] - (if (= :image type) - (let [fill-color (str/upper (:fill-color object)) - fill-opacity (:fill-opacity object)] - (cond-> object - (and (= 1 fill-opacity) - (or (= "#B1B2B5" fill-color) - (= "#7B7D85" fill-color))) - (dissoc :fill-color :fill-opacity))) - object)) + (letfn [(process-shape [shape] + (let [fill-color (str/upper (:fill-color shape)) + fill-opacity (:fill-opacity shape)] + (cond-> shape + (and (= 1 fill-opacity) + (or (= "#B1B2B5" fill-color) + (= "#7B7D85" fill-color))) + (dissoc :fill-color :fill-opacity)))) - (update-container [_ container] - (update container :objects #(d/mapm update-object %)))] + (update-container [_ {:keys [objects] :as container}] + (loop [objects objects + shapes (->> (vals objects) + (filter #(= :image (:type %))))] + (if-let [shape (first shapes)] + (let [{:keys [id frame-id] :as shape'} (process-shape shape)] + (if (identical? shape shape') + (recur objects (rest shapes)) + (recur (-> objects + (assoc id shape') + (d/update-when frame-id dissoc :thumbnail)) + (rest shapes)))) + (assoc container :objects objects))))] (-> data (update :pages-index #(d/mapm update-container %)) From ad9a7fdce8ec6200c02e6f2d3c813b4a45141920 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 30 Mar 2022 15:10:28 +0200 Subject: [PATCH 05/19] :paperclip: Set explicit clojure version on frontend and backend --- backend/deps.edn | 1 + frontend/deps.edn | 1 + 2 files changed, 2 insertions(+) diff --git a/backend/deps.edn b/backend/deps.edn index 42014d8fb..adb06499b 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -1,5 +1,6 @@ {:deps {penpot/common {:local/root "../common"} + org.clojure/clojure {:mvn/version "1.10.3"} org.clojure/core.async {:mvn/version "1.5.648"} ;; Logging diff --git a/frontend/deps.edn b/frontend/deps.edn index fefc86071..4cf48af87 100644 --- a/frontend/deps.edn +++ b/frontend/deps.edn @@ -3,6 +3,7 @@ {penpot/common {:local/root "../common"} + org.clojure/clojure {:mvn/version "1.10.3"} binaryage/devtools {:mvn/version "RELEASE"} metosin/reitit-core {:mvn/version "0.5.15"} From eaa6327663d77b5ef50e4cd50e90562112ee9312 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 31 Mar 2022 11:03:14 +0200 Subject: [PATCH 06/19] :bug: Fix issue with drag-select shapes --- CHANGES.md | 1 + frontend/src/app/main/data/workspace/selection.cljs | 5 ++++- frontend/src/app/main/ui/workspace/viewport.cljs | 2 +- frontend/src/app/main/ui/workspace/viewport/actions.cljs | 9 +++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d8f2b61f6..833f76de8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### :bug: Bugs fixed - Fix issue with shift+select to deselect shapes [Taiga #3154](https://tree.taiga.io/project/penpot/issue/3154) +- Fix issue with drag-select shapes [Taiga #3165](https://tree.taiga.io/project/penpot/issue/3165) ## 1.12.2-beta diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 08f2985e5..001bc27c4 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -104,7 +104,10 @@ (rx/dedupe) (rx/map #(select-shapes-by-current-selrect preserve? ignore-groups?)))) - (rx/of (update-selrect nil))))))) + (->> (rx/of (update-selrect nil)) + ;; We need the async so the current event finishes before updating the selrect + ;; otherwise the `on-click` event will trigger with a `nil` selrect + (rx/observe-on :async))))))) ;; --- Toggle shape's selection status (selected or deselected) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 943f796c4..a0d0c740f 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -116,7 +116,7 @@ node-editing? (and edition (not= :text (get-in base-objects [edition :type]))) text-editing? (and edition (= :text (get-in base-objects [edition :type]))) - on-click (actions/on-click hover selected edition drawing-path? drawing-tool space?) + on-click (actions/on-click hover selected edition drawing-path? drawing-tool space? selrect) on-context-menu (actions/on-context-menu hover hover-ids) on-double-click (actions/on-double-click hover hover-ids drawing-path? base-objects edition) on-drag-enter (actions/on-drag-enter) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index bb273a51a..6ac904151 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -142,12 +142,13 @@ (reset! frame-hover nil)))) (defn on-click - [hover selected edition drawing-path? drawing-tool space?] + [hover selected edition drawing-path? drawing-tool space? selrect] (mf/use-callback - (mf/deps @hover selected edition drawing-path? drawing-tool @space?) + (mf/deps @hover selected edition drawing-path? drawing-tool @space? selrect) (fn [event] - (when (or (dom/class? (dom/get-target event) "viewport-controls") - (dom/class? (dom/get-target event) "viewport-selrect")) + (when (and (nil? selrect) + (or (dom/class? (dom/get-target event) "viewport-controls") + (dom/class? (dom/get-target event) "viewport-selrect"))) (let [ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) alt? (kbd/alt? event) From b4a997cde9e0fd9bd89e71137da4e22742f4069c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 4 Apr 2022 23:46:42 +0200 Subject: [PATCH 07/19] :bug: Fix issue with password persistence --- CHANGES.md | 1 + backend/src/app/rpc/mutations/profile.clj | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 833f76de8..61e7fde3c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - Fix issue with shift+select to deselect shapes [Taiga #3154](https://tree.taiga.io/project/penpot/issue/3154) - Fix issue with drag-select shapes [Taiga #3165](https://tree.taiga.io/project/penpot/issue/3165) +- Fix issue on password persistence after registration process on private instances ## 1.12.2-beta diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 85acbe863..b286413fc 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -6,6 +6,7 @@ (ns app.rpc.mutations.profile (:require + [app.common.data :as d] [app.common.exceptions :as ex] [app.common.spec :as us] [app.common.uuid :as uuid] @@ -123,6 +124,7 @@ :hint "you can't use your email as password")) (let [params {:email (:email params) + :password (:password params) :invitation-token (:invitation-token params) :backend "penpot" :iss :prepared-register @@ -149,7 +151,6 @@ params (merge params claims)] (check-profile-existence! conn params) - (let [is-active (or (:is-active params) (contains? cf/flags :insecure-register)) profile (->> (assoc params :is-active is-active) From 1cac7d55d03c6a7edffdbde543a643cd8b205a73 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 16 Mar 2022 21:51:02 +0100 Subject: [PATCH 08/19] :bug: Fix crash on iOS when displaying viewer --- CHANGES.md | 6 ++++++ frontend/src/app/main/ui/viewer.cljs | 2 +- frontend/src/app/util/dom.cljs | 21 ++++++++++++--------- frontend/src/app/util/webapi.cljs | 14 +++++++++----- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 61e7fde3c..52816e2c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # CHANGELOG +## 1.12.4-beta + +### :bug: Bugs fixed + +- Fix crash on iOS when displaying viewer [#1522](https://github.com/penpot/penpot/issues/1522) + ## 1.12.3-beta ### :bug: Bugs fixed diff --git a/frontend/src/app/main/ui/viewer.cljs b/frontend/src/app/main/ui/viewer.cljs index 144c472d9..917a0c9d7 100644 --- a/frontend/src/app/main/ui/viewer.cljs +++ b/frontend/src/app/main/ui/viewer.cljs @@ -152,7 +152,7 @@ (mf/deps fullscreen?) (fn [] ;; Trigger dom fullscreen depending on our state - (let [wrapper (dom/get-element "viewer-layout") + (let [wrapper (dom/get-element "viewer-layout") fullscreen-dom? (dom/fullscreen?)] (when (not= fullscreen? fullscreen-dom?) (if fullscreen? diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index 15cbf004e..4398e9da8 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -6,13 +6,15 @@ (ns app.util.dom (:require - [app.common.exceptions :as ex] - [app.common.geom.point :as gpt] - [app.util.globals :as globals] - [app.util.object :as obj] - [cuerdas.core :as str] - [goog.dom :as dom] - [promesa.core :as p])) + [app.common.geom.point :as gpt] + [app.common.logging :as log] + [app.util.globals :as globals] + [app.util.object :as obj] + [cuerdas.core :as str] + [goog.dom :as dom] + [promesa.core :as p])) + +(log/set-level! :warn) ;; --- Deprecated methods @@ -289,8 +291,9 @@ (boolean (.-fullscreenElement globals/document)) :else - (ex/raise :type :not-supported - :hint "seems like the current browser does not support fullscreen api."))) + (do + (log/error :msg "Seems like the current browser does not support fullscreen api.") + false))) (defn ^boolean blob? [^js v] diff --git a/frontend/src/app/util/webapi.cljs b/frontend/src/app/util/webapi.cljs index 643d6d618..b56ac91a7 100644 --- a/frontend/src/app/util/webapi.cljs +++ b/frontend/src/app/util/webapi.cljs @@ -8,11 +8,13 @@ "HTML5 web api helpers." (:require [app.common.data :as d] - [app.common.exceptions :as ex] + [app.common.logging :as log] [app.util.object :as obj] [beicon.core :as rx] [cuerdas.core :as str])) +(log/set-level! :warn) + (defn- file-reader [f] (rx/create @@ -114,8 +116,9 @@ (.webkitRequestFullscreen el) :else - (ex/raise :type :not-supported - :hint "seems like the current browser does not support fullscreen api."))) + (do + (log/error :msg "Seems like the current browser does not support fullscreen api.") + false))) (defn exit-fullscreen [] @@ -127,8 +130,9 @@ (.webkitExitFullscreen js/document) :else - (ex/raise :type :not-supported - :hint "seems like the current browser does not support fullscreen api."))) + (do + (log/error :msg "Seems like the current browser does not support fullscreen api.") + false))) (defn observe-resize [node] From 0ed23f94c7e9081f34cb6136ab6a8232ca45cd79 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 22 Mar 2022 19:29:23 +0100 Subject: [PATCH 09/19] :bug: Fix problems with trackpad zoom and scroll in MacOS --- CHANGES.md | 1 + frontend/src/app/main/data/workspace.cljs | 1 - .../main/ui/workspace/viewport/actions.cljs | 48 +++++++++---------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 52816e2c5..1e1d96f2c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### :bug: Bugs fixed - Fix crash on iOS when displaying viewer [#1522](https://github.com/penpot/penpot/issues/1522) +- Fix problems with trackpad zoom and scroll in MacOS [#1161](https://github.com/penpot/penpot/issues/1161) ## 1.12.3-beta diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 59bc76e2e..2fce408fa 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -2102,4 +2102,3 @@ (d/export dwgu/update-guides) (d/export dwgu/remove-guide) (d/export dwgu/set-hover-guide) - diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index 6ac904151..bbdbddfa1 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -7,6 +7,7 @@ (ns app.main.ui.workspace.viewport.actions (:require [app.common.geom.point :as gpt] + [app.common.math :as mth] [app.common.uuid :as uuid] [app.config :as cfg] [app.main.data.workspace :as dw] @@ -359,27 +360,19 @@ (mf/use-callback (mf/deps zoom) (fn [event] - (let [event (.getBrowserEvent ^js event) - raw-pt (dom/get-client-position event) - viewport (mf/ref-val viewport-ref) - pt (utils/translate-point-to-viewport viewport zoom raw-pt) - - ctrl? (kbd/ctrl? event) - meta? (kbd/meta? event) + (let [viewport (mf/ref-val viewport-ref) + event (.getBrowserEvent ^js event) target (dom/get-target event)] - (cond - (or ctrl? meta?) - (do - (dom/prevent-default event) - (dom/stop-propagation event) - (let [delta (+ (.-deltaY ^js event) - (.-deltaX ^js event))] - (if (pos? delta) - (st/emit! (dw/decrease-zoom pt)) - (st/emit! (dw/increase-zoom pt))))) + (when (.contains ^js viewport target) + (dom/prevent-default event) + (dom/stop-propagation event) + (let [pt (->> (dom/get-client-position event) + (utils/translate-point-to-viewport viewport zoom)) - (.contains ^js viewport target) - (let [delta-mode (.-deltaMode ^js event) + ctrl? (kbd/ctrl? event) + meta? (kbd/meta? event) + + delta-mode (.-deltaMode ^js event) unit (cond (= delta-mode WheelEvent.DeltaMode.PIXEL) 1 @@ -393,13 +386,16 @@ delta-x (-> (.-deltaX ^js event) (* unit) (/ zoom))] - (dom/prevent-default event) - (dom/stop-propagation event) - (if (and (not (cfg/check-platform? :macos)) ;; macos sends delta-x automatically, don't need to do it - (kbd/shift? event)) - (st/emit! (dw/update-viewport-position {:x #(+ % delta-y)})) - (st/emit! (dw/update-viewport-position {:x #(+ % delta-x) - :y #(+ % delta-y)}))))))))) + (if (or ctrl? meta?) + (let [delta (* -1 (+ (.-deltaY ^js event) (.-deltaX ^js event))) + scale (-> (+ 1 (/ delta 100)) (mth/clamp 0.77 1.3))] + (st/emit! (dw/set-zoom pt scale))) + (if (and (not (cfg/check-platform? :macos)) + ;; macos sends delta-x automatically, don't need to do it + (kbd/shift? event)) + (st/emit! (dw/update-viewport-position {:x #(+ % delta-y)})) + (st/emit! (dw/update-viewport-position {:x #(+ % delta-x) + :y #(+ % delta-y)})))))))))) (defn on-drag-enter [] (mf/use-callback From 620efcb5cb81ee0ef4788760a3b045a5b14bbcbe Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 23 Mar 2022 14:20:54 +0100 Subject: [PATCH 10/19] :bug: Fix problem with copy/paste in Safari --- CHANGES.md | 1 + frontend/src/app/main/data/workspace.cljs | 40 ++++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1e1d96f2c..7d2e71504 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ - Fix crash on iOS when displaying viewer [#1522](https://github.com/penpot/penpot/issues/1522) - Fix problems with trackpad zoom and scroll in MacOS [#1161](https://github.com/penpot/penpot/issues/1161) +- Fix problem with copy/paste in Safari [#1209](https://github.com/penpot/penpot/issues/1209) ## 1.12.3-beta diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 2fce408fa..bedd0dd4c 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1548,13 +1548,10 @@ [] (letfn [;; Sort objects so they have the same relative ordering ;; when pasted later. - (sort-selected [state data] - (let [selected (:selected data) - page-id (:current-page-id state) - objects (get-in state [:workspace-data - :pages-index - page-id - :objects])] + (sort-selected-async [state data] + (let [selected (wsh/lookup-selected state) + objects (wsh/lookup-page-objects state) + page-id (:current-page-id state)] (->> (uw/ask! {:cmd :selection/query-z-index :page-id page-id :objects objects @@ -1566,6 +1563,24 @@ (map first) (into (d/ordered-set))))))))) + ;; We cannot call to a remote procedure in Safari (for the copy) so we need + ;; to calculate it here instead of on the worker + (sort-selected-sync [state data] + (let [selected (wsh/lookup-selected state) + objects (wsh/lookup-page-objects state) + z-index (cp/calculate-z-index objects) + z-values (->> selected + (map #(vector % + (+ (get z-index %) + (get z-index (get-in objects [% :frame-id])))))) + selected + (->> z-values + (sort-by second) + (map first) + (into (d/ordered-set)))] + + (assoc data :selected selected))) + ;; Retrieve all ids of selected shapes with corresponding ;; children; this is needed because each shape should be ;; processed one by one because of async events (data url @@ -1627,11 +1642,18 @@ :file-id (:current-file-id state) :selected selected :objects {} - :images #{}}] + :images #{}} + + sort-results + (fn [obs] + ;; Safari doesn't allow asynchronous sorting on the copy + (if (cfg/check-browser? :safari) + (rx/map (partial sort-selected-sync state) obs) + (rx/mapcat (partial sort-selected-async state) obs)))] (->> (rx/from (seq (vals pdata))) (rx/merge-map (partial prepare-object objects selected)) (rx/reduce collect-data initial) - (rx/mapcat (partial sort-selected state)) + (sort-results) (rx/map t/encode-str) (rx/map wapi/write-to-clipboard) (rx/catch on-copy-error) From adfc0902a2f46737b6092ee14792a142cc43c56d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 24 Mar 2022 14:45:52 +0100 Subject: [PATCH 11/19] :bug: Fix problems with CTRL in MacOS --- CHANGES.md | 1 + .../app/main/data/workspace/transforms.cljs | 10 ++-- frontend/src/app/main/streams.cljs | 50 ++++++++++++++++--- .../src/app/main/ui/settings/sidebar.cljs | 4 +- frontend/src/app/main/ui/viewer/handoff.cljs | 2 +- .../main/ui/viewer/handoff/left_sidebar.cljs | 2 +- .../src/app/main/ui/viewer/interactions.cljs | 2 +- .../main/ui/workspace/shapes/path/editor.cljs | 6 +-- .../app/main/ui/workspace/sidebar/assets.cljs | 2 +- .../app/main/ui/workspace/sidebar/layers.cljs | 2 +- .../src/app/main/ui/workspace/viewport.cljs | 12 ++--- .../main/ui/workspace/viewport/actions.cljs | 40 +++++++++------ .../app/main/ui/workspace/viewport/hooks.cljs | 28 +++++------ frontend/src/app/util/keyboard.cljs | 30 +++++++---- 14 files changed, 123 insertions(+), 68 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7d2e71504..98cbee0e8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ - Fix crash on iOS when displaying viewer [#1522](https://github.com/penpot/penpot/issues/1522) - Fix problems with trackpad zoom and scroll in MacOS [#1161](https://github.com/penpot/penpot/issues/1161) - Fix problem with copy/paste in Safari [#1209](https://github.com/penpot/penpot/issues/1209) +- Improved command support for MacOS [Taiga #2789](https://tree.taiga.io/project/penpot/issue/2789) ## 1.12.3-beta diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 8f5d3cc85..9a8bc6bbe 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -434,13 +434,13 @@ group (gsh/selection-rect shapes) group-center (gsh/center-selrect group) initial-angle (gpt/angle @ms/mouse-position group-center) - calculate-angle (fn [pos ctrl? shift?] + calculate-angle (fn [pos mod? shift?] (let [angle (- (gpt/angle pos group-center) initial-angle) angle (if (neg? angle) (+ 360 angle) angle) angle (if (= angle 360) 0 angle) - angle (if ctrl? + angle (if mod? (* (mth/floor (/ angle 45)) 45) angle) angle (if shift? @@ -449,10 +449,10 @@ angle))] (rx/concat (->> ms/mouse-position - (rx/with-latest vector ms/mouse-position-ctrl) + (rx/with-latest vector ms/mouse-position-mod) (rx/with-latest vector ms/mouse-position-shift) - (rx/map (fn [[[pos ctrl?] shift?]] - (let [delta-angle (calculate-angle pos ctrl? shift?)] + (rx/map (fn [[[pos mod?] shift?]] + (let [delta-angle (calculate-angle pos mod? shift?)] (set-rotation-modifiers delta-angle shapes group-center)))) (rx/take-until stoper)) (rx/of (apply-modifiers (map :id shapes)) diff --git a/frontend/src/app/main/streams.cljs b/frontend/src/app/main/streams.cljs index 7b5201ffa..759fddd23 100644 --- a/frontend/src/app/main/streams.cljs +++ b/frontend/src/app/main/streams.cljs @@ -7,6 +7,7 @@ (ns app.main.streams "User interaction events and streams." (:require + [app.config :as cfg] [app.main.store :as st] [app.util.globals :as globals] [app.util.keyboard :as kbd] @@ -20,7 +21,7 @@ [v] (instance? KeyboardEvent v)) -(defrecord MouseEvent [type ctrl shift alt]) +(defrecord MouseEvent [type ctrl shift alt meta]) (defn mouse-event? [v] @@ -46,7 +47,7 @@ (and (mouse-event? v) (= :double-click (:type v)))) -(defrecord PointerEvent [source pt ctrl shift alt]) +(defrecord PointerEvent [source pt ctrl shift alt meta]) (defn pointer-event? [v] @@ -83,6 +84,20 @@ (rx/subscribe-with ob sub) sub)) +(defonce mouse-position-meta + (let [sub (rx/behavior-subject nil) + ob (->> st/stream + (rx/filter pointer-event?) + (rx/map :meta) + (rx/dedupe))] + (rx/subscribe-with ob sub) + sub)) + +(defonce mouse-position-mod + (if (cfg/check-platform? :macos) + mouse-position-meta + mouse-position-ctrl)) + (defonce mouse-position-shift (let [sub (rx/behavior-subject nil) ob (->> st/stream @@ -111,7 +126,7 @@ ob (->> (rx/merge (->> st/stream (rx/filter keyboard-event?) - (rx/filter kbd/altKey?) + (rx/filter kbd/alt-key?) (rx/map #(= :down (:type %)))) ;; Fix a situation caused by using `ctrl+alt` kind of shortcuts, ;; that makes keyboard-alt stream registering the key pressed but @@ -119,15 +134,15 @@ (->> window-blur (rx/map (constantly false)))) (rx/dedupe))] - (rx/subscribe-with ob sub) - sub)) + (rx/subscribe-with ob sub) + sub)) (defonce keyboard-ctrl (let [sub (rx/behavior-subject nil) ob (->> (rx/merge (->> st/stream (rx/filter keyboard-event?) - (rx/filter kbd/ctrlKey?) + (rx/filter kbd/ctrl-key?) (rx/map #(= :down (:type %)))) ;; Fix a situation caused by using `ctrl+alt` kind of shortcuts, ;; that makes keyboard-alt stream registering the key pressed but @@ -135,9 +150,30 @@ (->> window-blur (rx/map (constantly false)))) (rx/dedupe))] - (rx/subscribe-with ob sub) + (rx/subscribe-with ob sub) sub)) +(defonce keyboard-meta + (let [sub (rx/behavior-subject nil) + ob (->> (rx/merge + (->> st/stream + (rx/filter keyboard-event?) + (rx/filter kbd/meta-key?) + (rx/map #(= :down (:type %)))) + ;; Fix a situation caused by using `ctrl+alt` kind of shortcuts, + ;; that makes keyboard-alt stream registering the key pressed but + ;; on blurring the window (unfocus) the key down is never arrived. + (->> window-blur + (rx/map (constantly false)))) + (rx/dedupe))] + (rx/subscribe-with ob sub) + sub)) + +(defonce keyboard-mod + (if (cfg/check-platform? :macos) + keyboard-meta + keyboard-ctrl)) + (defonce keyboard-space (let [sub (rx/behavior-subject nil) ob (->> st/stream diff --git a/frontend/src/app/main/ui/settings/sidebar.cljs b/frontend/src/app/main/ui/settings/sidebar.cljs index 0b9cce30d..3a5504fe9 100644 --- a/frontend/src/app/main/ui/settings/sidebar.cljs +++ b/frontend/src/app/main/ui/settings/sidebar.cljs @@ -14,6 +14,7 @@ [app.main.ui.dashboard.sidebar :refer [profile-section]] [app.main.ui.icons :as i] [app.util.i18n :as i18n :refer [tr]] + [app.util.keyboard :as kbd] [app.util.router :as rt] [potok.core :as ptk] [rumext.alpha :as mf])) @@ -55,8 +56,7 @@ (fn [event] (let [version (:main @cf/version)] (st/emit! (ptk/event ::ev/event {::ev/name "show-release-notes" :version version})) - (if (and (.-ctrlKey ^js event) - (.-altKey ^js event)) + (if (and (kbd/alt? event) (kbd/mod? event)) (st/emit! (modal/show {:type :onboarding})) (st/emit! (modal/show {:type :release-notes :version version}))))))] diff --git a/frontend/src/app/main/ui/viewer/handoff.cljs b/frontend/src/app/main/ui/viewer/handoff.cljs index f3cbeaa7b..4a00631ea 100644 --- a/frontend/src/app/main/ui/viewer/handoff.cljs +++ b/frontend/src/app/main/ui/viewer/handoff.cljs @@ -28,7 +28,7 @@ [{:keys [local file page frame]}] (let [on-mouse-wheel (fn [event] - (when (or (kbd/ctrl? event) (kbd/meta? event)) + (when (kbd/mod? event) (dom/prevent-default event) (let [event (.getBrowserEvent ^js event) delta (+ (.-deltaY ^js event) diff --git a/frontend/src/app/main/ui/viewer/handoff/left_sidebar.cljs b/frontend/src/app/main/ui/viewer/handoff/left_sidebar.cljs index 4319c262d..4e05ac409 100644 --- a/frontend/src/app/main/ui/viewer/handoff/left_sidebar.cljs +++ b/frontend/src/app/main/ui/viewer/handoff/left_sidebar.cljs @@ -45,7 +45,7 @@ (dom/prevent-default event) (let [id (:id item)] (cond - (or (kbd/ctrl? event) (kbd/meta? event)) + (kbd/mod? event) (st/emit! (dv/toggle-selection id)) (kbd/shift? event) diff --git a/frontend/src/app/main/ui/viewer/interactions.cljs b/frontend/src/app/main/ui/viewer/interactions.cljs index e3e0b55b4..587b41ac9 100644 --- a/frontend/src/app/main/ui/viewer/interactions.cljs +++ b/frontend/src/app/main/ui/viewer/interactions.cljs @@ -61,7 +61,7 @@ on-mouse-wheel (fn [event] - (when (or (kbd/ctrl? event) (kbd/meta? event)) + (when (kbd/mod? event) (dom/prevent-default event) (let [event (.getBrowserEvent ^js event) delta (+ (.-deltaY ^js event) (.-deltaX ^js event))] diff --git a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs index 2ccc1583d..36d0fcf41 100644 --- a/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/path/editor.cljs @@ -47,15 +47,15 @@ (st/emit! (drp/create-node-at-position (meta position)))) (let [shift? (kbd/shift? event) - ctrl? (kbd/ctrl? event)] + mod? (kbd/mod? event)] (cond last-p? (st/emit! (drp/reset-last-handler)) - (and (= edit-mode :move) ctrl? (not curve?)) + (and (= edit-mode :move) mod? (not curve?)) (st/emit! (drp/make-curve position)) - (and (= edit-mode :move) ctrl? curve?) + (and (= edit-mode :move) mod? curve?) (st/emit! (drp/make-corner position)) (= edit-mode :move) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index 8ed877406..903e3c7d5 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -1485,7 +1485,7 @@ (mf/deps extend-selected-assets selected-assets) (fn [asset-type asset-groups event asset-id default-click] (cond - (kbd/ctrl? event) + (kbd/mod? event) (do (dom/stop-propagation event) (st/emit! (dw/toggle-selected-assets asset-id asset-type))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/layers.cljs b/frontend/src/app/main/ui/workspace/sidebar/layers.cljs index 9e65bbf54..b077c1ee3 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layers.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layers.cljs @@ -133,7 +133,7 @@ (kbd/shift? event) (st/emit! (dw/shift-select-shapes id)) - (or (kbd/ctrl? event) (kbd/meta? event)) + (kbd/mod? event) (st/emit! (dw/select-shape id true)) (> (count selected) 1) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index a0d0c740f..13321c3fd 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -73,7 +73,7 @@ ;; STATE alt? (mf/use-state false) - ctrl? (mf/use-state false) + mod? (mf/use-state false) space? (mf/use-state false) cursor (mf/use-state (utils/get-cursor :pointer-inner)) hover-ids (mf/use-state nil) @@ -163,9 +163,9 @@ (hooks/setup-dom-events viewport-ref zoom disable-paste in-viewport?) (hooks/setup-viewport-size viewport-ref) - (hooks/setup-cursor cursor alt? ctrl? space? panning drawing-tool drawing-path? node-editing?) - (hooks/setup-keyboard alt? ctrl? space?) - (hooks/setup-hover-shapes page-id move-stream raw-position-ref base-objects transform selected ctrl? hover hover-ids @hover-disabled? zoom) + (hooks/setup-cursor cursor alt? mod? space? panning drawing-tool drawing-path? node-editing?) + (hooks/setup-keyboard alt? mod? space?) + (hooks/setup-hover-shapes page-id move-stream raw-position-ref base-objects transform selected mod? hover hover-ids @hover-disabled? zoom) (hooks/setup-viewport-modifiers modifiers base-objects) (hooks/setup-shortcuts node-editing? drawing-path?) (hooks/setup-active-frames base-objects vbox hover active-frames) @@ -244,7 +244,7 @@ [:& outline/shape-outlines {:objects base-objects :selected selected - :hover (when (or @ctrl? (not= :frame (:type @hover))) + :hover (when (or @mod? (not= :frame (:type @hover))) #{(or @frame-hover (:id @hover))}) :edition edition :zoom zoom}]) @@ -254,7 +254,7 @@ {:shapes selected-shapes :zoom zoom :edition edition - :disable-handlers (or drawing-tool edition @space? @ctrl?) + :disable-handlers (or drawing-tool edition @space? @mod?) :on-move-selected on-move-selected :on-context-menu on-menu-selected}]) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index bbdbddfa1..2be7787c1 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -41,8 +41,10 @@ (let [event (.-nativeEvent bevent) ctrl? (kbd/ctrl? event) + meta? (kbd/meta? event) shift? (kbd/shift? event) alt? (kbd/alt? event) + mod? (kbd/mod? event) left-click? (and (not panning) (= 1 (.-which event))) middle-click? (and (not panning) (= 2 (.-which event))) @@ -54,7 +56,7 @@ middle-click? (do (dom/prevent-default bevent) - (if ctrl? + (if mod? (let [raw-pt (dom/get-client-position event) viewport (mf/ref-val viewport-ref) pt (utils/translate-point-to-viewport viewport zoom raw-pt)] @@ -64,7 +66,7 @@ left-click? (do - (st/emit! (ms/->MouseEvent :down ctrl? shift? alt?)) + (st/emit! (ms/->MouseEvent :down ctrl? shift? alt? meta?)) (when (and (not= edition id) text-editing?) (st/emit! dw/clear-edition-mode)) @@ -79,7 +81,7 @@ ;; Handle path node area selection (st/emit! (dwdp/handle-area-selection shift?)) - (and @space? ctrl?) + (and @space? mod?) (let [raw-pt (dom/get-client-position event) viewport (mf/ref-val viewport-ref) pt (utils/translate-point-to-viewport viewport zoom raw-pt)] @@ -91,8 +93,8 @@ drawing-tool (st/emit! (dd/start-drawing drawing-tool)) - (or (not id) (and frame? (not selected?)) ctrl?) - (st/emit! (dw/handle-area-selection shift? ctrl?)) + (or (not id) (and frame? (not selected?)) mod?) + (st/emit! (dw/handle-area-selection shift? mod?)) (not drawing-tool) (st/emit! (dw/start-move-selected id shift?))))))))))) @@ -104,11 +106,11 @@ (fn [bevent] (let [event (.-nativeEvent bevent) shift? (kbd/shift? event) - ctrl? (kbd/ctrl? event) + mod? (kbd/mod? event) left-click? (= 1 (.-which event))] (when (and left-click? - (not ctrl?) + (not mod?) (not shift?) (not @space?) (or (not @hover) @@ -153,12 +155,15 @@ (let [ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) alt? (kbd/alt? event) + meta? (kbd/meta? event) + mod? (kbd/mod? event) + hovering? (some? @hover) frame? (= :frame (:type @hover))] - (st/emit! (ms/->MouseEvent :click ctrl? shift? alt?)) + (st/emit! (ms/->MouseEvent :click ctrl? shift? alt? meta?)) (when (and hovering? - (or (not frame?) ctrl?) + (or (not frame?) mod?) (not @space?) (not edition) (not drawing-path?) @@ -174,13 +179,14 @@ (let [ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) alt? (kbd/alt? event) + meta? (kbd/meta? event) {:keys [id type] :as shape} @hover frame? (= :frame type) group? (= :group type)] - (st/emit! (ms/->MouseEvent :double-click ctrl? shift? alt?)) + (st/emit! (ms/->MouseEvent :double-click ctrl? shift? alt? meta?)) ;; Emit asynchronously so the double click to exit shapes won't break (timers/schedule @@ -239,12 +245,13 @@ ctrl? (kbd/ctrl? event) shift? (kbd/shift? event) alt? (kbd/alt? event) + meta? (kbd/meta? event) left-click? (= 1 (.-which event)) middle-click? (= 2 (.-which event))] (when left-click? - (st/emit! (ms/->MouseEvent :up ctrl? shift? alt?))) + (st/emit! (ms/->MouseEvent :up ctrl? shift? alt? meta?))) (when middle-click? (dom/prevent-default event) @@ -340,11 +347,13 @@ (st/emit! (ms/->PointerEvent :delta delta (kbd/ctrl? event) (kbd/shift? event) - (kbd/alt? event))) + (kbd/alt? event) + (kbd/meta? event))) (st/emit! (ms/->PointerEvent :viewport pt (kbd/ctrl? event) (kbd/shift? event) - (kbd/alt? event)))))))) + (kbd/alt? event) + (kbd/meta? event)))))))) (defn on-pointer-move [viewport-ref raw-position-ref zoom move-stream] (mf/use-callback @@ -369,8 +378,7 @@ (let [pt (->> (dom/get-client-position event) (utils/translate-point-to-viewport viewport zoom)) - ctrl? (kbd/ctrl? event) - meta? (kbd/meta? event) + mod? (kbd/mod? event) delta-mode (.-deltaMode ^js event) @@ -386,7 +394,7 @@ delta-x (-> (.-deltaX ^js event) (* unit) (/ zoom))] - (if (or ctrl? meta?) + (if mod? (let [delta (* -1 (+ (.-deltaY ^js event) (.-deltaX ^js event))) scale (-> (+ 1 (/ delta 100)) (mth/clamp 0.77 1.3))] (st/emit! (dw/set-zoom pt scale))) diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index f9b7ca0c2..00361b7d1 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -58,13 +58,13 @@ ;; We schedule the event so it fires after `initialize-page` event (timers/schedule #(st/emit! (dw/initialize-viewport size))))))) -(defn setup-cursor [cursor alt? ctrl? space? panning drawing-tool drawing-path? path-editing?] +(defn setup-cursor [cursor alt? mod? space? panning drawing-tool drawing-path? path-editing?] (mf/use-effect - (mf/deps @cursor @alt? @ctrl? @space? panning drawing-tool drawing-path? path-editing?) + (mf/deps @cursor @alt? @mod? @space? panning drawing-tool drawing-path? path-editing?) (fn [] (let [new-cursor (cond - (and @ctrl? @space?) (utils/get-cursor :zoom) + (and @mod? @space?) (utils/get-cursor :zoom) (or panning @space?) (utils/get-cursor :hand) (= drawing-tool :comments) (utils/get-cursor :comments) (= drawing-tool :frame) (utils/get-cursor :create-artboard) @@ -80,9 +80,9 @@ (when (not= @cursor new-cursor) (reset! cursor new-cursor)))))) -(defn setup-keyboard [alt? ctrl? space?] +(defn setup-keyboard [alt? mod? space?] (hooks/use-stream ms/keyboard-alt #(reset! alt? %)) - (hooks/use-stream ms/keyboard-ctrl #(reset! ctrl? %)) + (hooks/use-stream ms/keyboard-mod #(reset! mod? %)) (hooks/use-stream ms/keyboard-space #(reset! space? %))) (defn group-empty-space? @@ -108,10 +108,10 @@ (map dom/bounding-rect->rect))] (not (some #(gshr/contains-point? % pos) collisions))))) -(defn setup-hover-shapes [page-id move-stream raw-position-ref objects transform selected ctrl? hover hover-ids hover-disabled? zoom] +(defn setup-hover-shapes [page-id move-stream raw-position-ref objects transform selected mod? hover hover-ids hover-disabled? zoom] (let [;; We use ref so we don't recreate the stream on a change zoom-ref (mf/use-ref zoom) - ctrl-ref (mf/use-ref @ctrl?) + mod-ref (mf/use-ref @mod?) transform-ref (mf/use-ref nil) selected-ref (mf/use-ref selected) hover-disabled-ref (mf/use-ref hover-disabled?) @@ -121,7 +121,7 @@ (mf/deps page-id) (fn [point] (let [zoom (mf/ref-val zoom-ref) - ctrl? (mf/ref-val ctrl-ref) + mod? (mf/ref-val mod-ref) rect (gsh/center->rect point (/ 5 zoom) (/ 5 zoom))] (if (mf/ref-val hover-disabled-ref) (rx/of nil) @@ -130,7 +130,7 @@ :page-id page-id :rect rect :include-frames? true - :clip-children? (not ctrl?) + :clip-children? (not mod?) :reverse? true}))))) ;; we want the topmost shape to be selected first over-shapes-stream @@ -157,8 +157,8 @@ #(mf/set-ref-val! zoom-ref zoom)) (mf/use-effect - (mf/deps @ctrl?) - #(mf/set-ref-val! ctrl-ref @ctrl?)) + (mf/deps @mod?) + #(mf/set-ref-val! mod-ref @mod?)) (mf/use-effect (mf/deps selected) @@ -178,17 +178,17 @@ selected (mf/ref-val selected-ref) - ctrl? (mf/ref-val ctrl-ref) + mod? (mf/ref-val mod-ref) remove-xfm (mapcat #(cph/get-parent-ids objects %)) remove-id? (cond-> (into #{} remove-xfm selected) :always (into (filter #(check-text-collision? objects (mf/ref-val raw-position-ref) %)) ids) - (not ctrl?) + (not mod?) (into (filter #(group-empty-space? % objects ids)) ids) - ctrl? + mod? (into (filter is-group?) ids)) hover-shape (->> ids diff --git a/frontend/src/app/util/keyboard.cljs b/frontend/src/app/util/keyboard.cljs index 0fb84f09d..52077fb30 100644 --- a/frontend/src/app/util/keyboard.cljs +++ b/frontend/src/app/util/keyboard.cljs @@ -4,37 +4,47 @@ ;; ;; Copyright (c) UXBOX Labs SL -(ns app.util.keyboard) +(ns app.util.keyboard + (:require + [app.config :as cfg])) (defn is-key? - [key] - (fn [e] + [^string key] + (fn [^js e] (= (.-key e) key))) (defn ^boolean alt? - [event] + [^js event] (.-altKey event)) (defn ^boolean ctrl? - [event] + [^js event] (.-ctrlKey event)) (defn ^boolean meta? - [event] + [^js event] (.-metaKey event)) (defn ^boolean shift? - [event] + [^js event] (.-shiftKey event)) +(defn ^boolean mod? + [^js event] + (if (cfg/check-platform? :macos) + (meta? event) + (ctrl? event))) + (def esc? (is-key? "Escape")) (def enter? (is-key? "Enter")) (def space? (is-key? " ")) (def up-arrow? (is-key? "ArrowUp")) (def down-arrow? (is-key? "ArrowDown")) -(def altKey? (is-key? "Alt")) -(def ctrlKey? (or (is-key? "Control") - (is-key? "Meta"))) +(def alt-key? (is-key? "Alt")) +(def ctrl-key? (is-key? "Control")) +(def meta-key? (is-key? "Meta")) +(def comma? (is-key? ",")) +(def backspace? (is-key? "Backspace")) (defn editing? [e] (.-editing ^js e)) From 9ffe406d0d995f1a864f8b1d837d7052a53ebaab Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 24 Mar 2022 16:56:01 +0100 Subject: [PATCH 12/19] :bug: Fix shift+2 shortcut in MacOS with non-english keyboards --- CHANGES.md | 1 + frontend/src/app/main/data/workspace/shortcuts.cljs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 98cbee0e8..5e13c092b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ - Fix problems with trackpad zoom and scroll in MacOS [#1161](https://github.com/penpot/penpot/issues/1161) - Fix problem with copy/paste in Safari [#1209](https://github.com/penpot/penpot/issues/1209) - Improved command support for MacOS [Taiga #2789](https://tree.taiga.io/project/penpot/issue/2789) +- Fix shift+2 shortcut in MacOS with non-english keyboards [Taiga #3038](https://tree.taiga.io/project/penpot/issue/3038) ## 1.12.3-beta diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index bb5a2539b..4814692f1 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -134,7 +134,7 @@ :fn #(st/emit! dw/zoom-to-fit-all)} :zoom-selected {:tooltip (ds/shift "2") - :command "shift+2" + :command ["shift+2" "@" "\""] :fn #(st/emit! dw/zoom-to-selected-shape)} :duplicate {:tooltip (ds/meta "D") From 2ae2877f45f0f07e593e1c4a21e669fcfaebeda7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 6 Apr 2022 09:40:20 +0200 Subject: [PATCH 13/19] :sparkles: Improve email console logging And invitation console logging --- backend/src/app/emails.clj | 29 +++++++++++++++---------- backend/src/app/rpc/mutations/teams.clj | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/backend/src/app/emails.clj b/backend/src/app/emails.clj index 6721c299c..1a5aebb63 100644 --- a/backend/src/app/emails.clj +++ b/backend/src/app/emails.clj @@ -8,6 +8,7 @@ "Main api for send emails." (:require [app.common.logging :as l] + [app.common.pprint :as pp] [app.common.spec :as us] [app.config :as cf] [app.db :as db] @@ -165,19 +166,25 @@ (let [enabled? (or (contains? cf/flags :smtp) (cf/get :smtp-enabled) (:enabled task))] - (if enabled? - (emails/send! cfg props) + (when enabled? + (emails/send! cfg props)) + + (when (contains? cf/flags :log-emails) (send-console! cfg props))))) (defn- send-console! [cfg email] - (let [baos (java.io.ByteArrayOutputStream.) - mesg (emails/smtp-message cfg email)] - (.writeTo mesg baos) - (let [out (with-out-str - (println "email console dump:") - (println "******** start email" (:id email) "**********") - (println (.toString baos)) - (println "******** end email "(:id email) "**********"))] - (l/info :email out)))) + (let [body (:body email) + out (with-out-str + (println "email console dump:") + (println "******** start email" (:id email) "**********") + (pp/pprint (dissoc email :body)) + (if (string? body) + (println body) + (println (->> body + (filter #(= "text/plain" (:type %))) + (map :content) + first))) + (println "******** end email" (:id email) "**********"))] + (l/info ::l/raw out))) diff --git a/backend/src/app/rpc/mutations/teams.clj b/backend/src/app/rpc/mutations/teams.clj index a104f3604..a06815b6a 100644 --- a/backend/src/app/rpc/mutations/teams.clj +++ b/backend/src/app/rpc/mutations/teams.clj @@ -8,6 +8,7 @@ (:require [app.common.data :as d] [app.common.exceptions :as ex] + [app.common.logging :as l] [app.common.spec :as us] [app.common.uuid :as uuid] [app.config :as cf] @@ -374,6 +375,9 @@ {:iss :profile-identity :profile-id (:id profile)})] + (when (contains? cf/flags :log-invitation-tokens) + (l/trace :hint "invitation token" :token itoken)) + (when (and member (not (eml/allow-send-emails? conn member))) (ex/raise :type :validation :code :member-is-muted From 175f4b57f52ce08d9dd2843457dac819e7335821 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 18 Apr 2022 16:41:35 +0200 Subject: [PATCH 14/19] :bug: Fix problem with ctrl+click context menu in mac --- .../src/app/main/ui/components/dropdown.cljs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/ui/components/dropdown.cljs b/frontend/src/app/main/ui/components/dropdown.cljs index 114617fa5..507af1f4d 100644 --- a/frontend/src/app/main/ui/components/dropdown.cljs +++ b/frontend/src/app/main/ui/components/dropdown.cljs @@ -6,7 +6,9 @@ (ns app.main.ui.components.dropdown (:require + [app.config :as cfg] [app.util.dom :as dom] + [app.util.globals :as globals] [app.util.keyboard :as kbd] [goog.events :as events] [goog.object :as gobj] @@ -22,8 +24,13 @@ on-click (fn [event] - (let [target (dom/get-target event)] - (when-not (.-data-no-close ^js target) + (let [target (dom/get-target event) + + ;; MacOS ctrl+click sends two events: context-menu and click. + ;; In order to not have two handlings we ignore ctrl+click for this platform + mac-ctrl-click? (and (cfg/check-platform? :macos) (kbd/ctrl? event))] + (when (and (not mac-ctrl-click?) + (not (.-data-no-close ^js target))) (if ref (let [parent (mf/ref-val ref)] (when-not (or (not parent) (.contains parent target)) @@ -37,9 +44,9 @@ on-mount (fn [] - (let [keys [(events/listen js/document EventType.CLICK on-click) - (events/listen js/document EventType.CONTEXTMENU on-click) - (events/listen js/document EventType.KEYUP on-keyup)]] + (let [keys [(events/listen globals/document EventType.CLICK on-click) + (events/listen globals/document EventType.CONTEXTMENU on-click) + (events/listen globals/document EventType.KEYUP on-keyup)]] #(doseq [key keys] (events/unlistenByKey key))))] From 7b3ab2287a199133acb0f055ca846ace25e45891 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 19 Apr 2022 12:07:06 +0200 Subject: [PATCH 15/19] :tada: Backport pprint module to common --- common/src/app/common/pprint.cljc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 common/src/app/common/pprint.cljc diff --git a/common/src/app/common/pprint.cljc b/common/src/app/common/pprint.cljc new file mode 100644 index 000000000..46ed119c7 --- /dev/null +++ b/common/src/app/common/pprint.cljc @@ -0,0 +1,26 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) UXBOX Labs SL + +(ns app.common.pprint + (:refer-clojure :exclude [prn]) + (:require + [fipp.edn :as fpp])) + +(defn pprint-str + [expr] + (binding [*print-level* 8 + *print-length* 25] + (with-out-str + (fpp/pprint expr {:width 110})))) + +(defn pprint + ([expr] + (println (pprint-str expr))) + ([label expr] + (println (str "============ " label "============")) + (pprint expr))) + + From a579ea3c2558f151bd4abf769a034921ec10ca54 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 19 Apr 2022 13:21:45 +0200 Subject: [PATCH 16/19] :bug: Fix pinch to zoom on mac --- frontend/src/app/main/ui/workspace/viewport/actions.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index 2be7787c1..e615d3903 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -379,6 +379,7 @@ (utils/translate-point-to-viewport viewport zoom)) mod? (kbd/mod? event) + ctrl? (kbd/ctrl? event) delta-mode (.-deltaMode ^js event) @@ -394,7 +395,7 @@ delta-x (-> (.-deltaX ^js event) (* unit) (/ zoom))] - (if mod? + (if (or ctrl? mod?) (let [delta (* -1 (+ (.-deltaY ^js event) (.-deltaX ^js event))) scale (-> (+ 1 (/ delta 100)) (mth/clamp 0.77 1.3))] (st/emit! (dw/set-zoom pt scale))) From cfe374b08c85b43196d1e36b89392cd4b9964948 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 20 Apr 2022 11:26:01 +0200 Subject: [PATCH 17/19] :paperclip: Tag new minor release --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 6907484ac..a9d6c88c5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.12.3-beta +1.12.4-beta From 58cfd619973ccc4e3acbc972de0acf2969988c53 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 22 Apr 2022 11:48:18 +0200 Subject: [PATCH 18/19] :bug: Don't send url on file-media-upload --- frontend/src/app/main/data/workspace/svg_upload.cljs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index b649250aa..148e9cb2e 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -431,15 +431,14 @@ ;; all shapes. (->> (rx/from (usvg/collect-images svg-data)) (rx/map (fn [uri] - (d/merge + (merge {:file-id file-id - :is-local true - :url uri} - + :is-local true} (if (str/starts-with? uri "data:") {:name "image" :content (uu/data-uri->blob uri)} - {:name (uu/uri-name uri)})))) + {:name (uu/uri-name uri) + :url uri})))) (rx/mapcat (fn [uri-data] (->> (rp/mutation! (if (contains? uri-data :content) :upload-file-media-object From e0aeb3b5ac52d0bcd16b848c74c5507416515745 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 22 Apr 2022 11:51:35 +0200 Subject: [PATCH 19/19] :paperclip: Reduce default chunk size of the audit log archive task --- backend/src/app/loggers/audit.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/app/loggers/audit.clj b/backend/src/app/loggers/audit.clj index 661b824b0..d970fdcd6 100644 --- a/backend/src/app/loggers/audit.clj +++ b/backend/src/app/loggers/audit.clj @@ -253,7 +253,7 @@ "select * from audit_log where archived_at is null order by created_at asc - limit 1000 + limit 256 for update skip locked;") (defn archive-events