0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 00:01:51 -05:00

Add shortcuts for dashboard viewer and path

This commit is contained in:
eva 2021-12-10 11:56:13 +01:00 committed by Alonso Torres
parent 8072caeff1
commit 771bb20976
8 changed files with 145 additions and 54 deletions

View file

@ -790,3 +790,46 @@
(watch [_ state _] (watch [_ state _]
(let [team-id (:current-team-id state)] (let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-team-settings {:team-id team-id})))))) (rx/of (rt/nav :dashboard-team-settings {:team-id team-id}))))))
(defn go-to-drafts
[]
(ptk/reify ::go-to-drafts
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)
projects (:dashboard-projects state)
default-project (d/seek :is-default (vals projects))]
(when default-project
(rx/of (rt/nav :dashboard-files {:team-id team-id
:project-id (:id default-project)})))))))
(defn go-to-libs
[]
(ptk/reify ::go-to-libs
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(rx/of (rt/nav :dashboard-libraries {:team-id team-id}))))))
(defn create-element
[]
(ptk/reify ::create-element
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)
route (:route state)
pparams (:path-params route)
in-project? (contains? pparams :project-id)
name (if in-project?
(name (gensym (str (tr "dashboard.new-file-prefix") " ")))
(name (gensym (str (tr "dashboard.new-project-prefix") " "))))
params (if in-project?
{:project-id (:project-id pparams)
:name name}
{:name name
:team-id team-id})
action-name (if in-project? :create-file :create-project)
action (if in-project? file-created project-created)]
(->> (rp/mutation! action-name params)
(rx/map action))))))

View file

@ -0,0 +1,33 @@
;; 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.main.data.dashboard.shortcuts
(:require
[app.main.data.dashboard :as dd]
[app.main.data.shortcuts :as ds]
[app.main.store :as st]
))
(def shortcuts
{:go-to-search {:tooltip (ds/meta "F")
:command (ds/c-mod "f")
:fn (st/emitf (dd/go-to-search))}
:go-to-drafts {:tooltip "G D"
:command "g d"
:fn (st/emitf (dd/go-to-drafts))}
:go-to-libs {:tooltip "G L"
:command "g l"
:fn (st/emitf (dd/go-to-libs))}
:create-new-project {:tooltip "+"
:command "+"
:fn (st/emitf (dd/create-element))}})
(defn get-tooltip [shortcut]
(assert (contains? shortcuts shortcut) (str shortcut))
(get-in shortcuts [shortcut :tooltip]))

View file

@ -544,18 +544,17 @@
(rx/of (rt/nav rname pparams qparams)))))) (rx/of (rt/nav rname pparams qparams))))))
(defn go-to-workspace (defn go-to-workspace
[page-id] ([] (go-to-workspace nil))
(ptk/reify ::go-to-workspace ([page-id]
ptk/WatchEvent (ptk/reify ::go-to-workspace
(watch [_ state _] ptk/WatchEvent
(let [project-id (get-in state [:viewer :project :id]) (watch [_ state _]
file-id (get-in state [:viewer :file :id]) (let [project-id (get-in state [:viewer :project :id])
pparams {:project-id project-id :file-id file-id} file-id (get-in state [:viewer :file :id])
qparams {:page-id page-id}] pparams {:project-id project-id :file-id file-id}
qparams {:page-id (or page-id (:current-page-id state))}]
(rx/of (rt/nav-new-window* (rx/of (rt/nav-new-window*
{:rname :workspace {:rname :workspace
:path-params pparams :path-params pparams
:query-params qparams :query-params qparams
:name (str "workspace-" file-id)})))))) :name (str "workspace-" file-id)})))))))

View file

@ -11,45 +11,49 @@
[app.main.store :as st])) [app.main.store :as st]))
(def shortcuts (def shortcuts
{:increase-zoom {:tooltip "+" {:increase-zoom {:tooltip "+"
:command "+" :command "+"
:fn (st/emitf dv/increase-zoom)} :fn (st/emitf dv/increase-zoom)}
:decrease-zoom {:tooltip "-" :decrease-zoom {:tooltip "-"
:command "-" :command "-"
:fn (st/emitf dv/decrease-zoom)} :fn (st/emitf dv/decrease-zoom)}
:select-all {:tooltip (ds/meta "A") :select-all {:tooltip (ds/meta "A")
:command (ds/c-mod "a") :command (ds/c-mod "a")
:fn (st/emitf (dv/select-all))} :fn (st/emitf (dv/select-all))}
:zoom-50 {:tooltip (ds/shift "0") :zoom-50 {:tooltip (ds/shift "0")
:command "shift+0" :command "shift+0"
:fn (st/emitf dv/zoom-to-50)} :fn (st/emitf dv/zoom-to-50)}
:reset-zoom {:tooltip (ds/shift "1") :reset-zoom {:tooltip (ds/shift "1")
:command "shift+1" :command "shift+1"
:fn (st/emitf dv/reset-zoom)} :fn (st/emitf dv/reset-zoom)}
:zoom-200 {:tooltip (ds/shift "2") :zoom-200 {:tooltip (ds/shift "2")
:command "shift+2" :command "shift+2"
:fn (st/emitf dv/zoom-to-200)} :fn (st/emitf dv/zoom-to-200)}
:next-frame {:tooltip ds/left-arrow :next-frame {:tooltip ds/left-arrow
:command "left" :command "left"
:fn (st/emitf dv/select-prev-frame)} :fn (st/emitf dv/select-prev-frame)}
:prev-frame {:tooltip ds/right-arrow :prev-frame {:tooltip ds/right-arrow
:command "right" :command "right"
:fn (st/emitf dv/select-next-frame)} :fn (st/emitf dv/select-next-frame)}
:open-handoff {:tooltip "G H" :open-handoff {:tooltip "G H"
:command "g h" :command "g h"
:fn #(st/emit! (dv/go-to-section :handoff))} :fn #(st/emit! (dv/go-to-section :handoff))}
:open-comments {:tooltip "G C" :open-comments {:tooltip "G C"
:command "g c" :command "g c"
:fn #(st/emit! (dv/go-to-section :comments))}}) :fn #(st/emit! (dv/go-to-section :comments))}
:open-workspace {:tooltip "G W"
:command "g w"
:fn #(st/emit! (dv/go-to-workspace))}})
(defn get-tooltip [shortcut] (defn get-tooltip [shortcut]
(assert (contains? shortcuts shortcut) (str shortcut)) (assert (contains? shortcuts shortcut) (str shortcut))

View file

@ -6,6 +6,7 @@
(ns app.main.data.workspace (ns app.main.data.workspace
(:require (:require
[app.common.attrs :as attrs]
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.align :as gal] [app.common.geom.align :as gal]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
@ -1199,12 +1200,19 @@
(rx/of (dch/update-shapes [id] assign-proportions)))))) (rx/of (dch/update-shapes [id] assign-proportions))))))
(defn toggle-proportion-lock (defn toggle-proportion-lock
[] []
(ptk/reify ::toggle-propotion-lock (ptk/reify ::toggle-propotion-lock
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [selected (wsh/lookup-selected state)] (let [page-id (:current-page-id state)
(rx/of (dch/update-shapes selected #(update % :proportion-lock not))))))) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)
selected-obj (-> (map #(get objects %) selected))
multi (attrs/get-attrs-multi selected-obj [:proportion-lock])
multi? (= :multiple (:proportion-lock multi))]
(if multi?
(rx/of (dch/update-shapes selected #(assoc % :proportion-lock true)))
(rx/of (dch/update-shapes selected #(update % :proportion-lock not))))))))
;; --- Update Shape Flags ;; --- Update Shape Flags

View file

@ -20,7 +20,7 @@
[potok.core :as ptk])) [potok.core :as ptk]))
;; Change this to :info :debug or :trace to debug this module ;; Change this to :info :debug or :trace to debug this module
(log/set-level! :warn) (log/set-level! :debug)
(s/def ::coll-of-uuid (s/def ::coll-of-uuid
(s/every ::us/uuid)) (s/every ::us/uuid))

View file

@ -32,8 +32,8 @@
(rx/empty)))))) (rx/empty))))))
(def shortcuts (def shortcuts
{:move-nodes {:tooltip "V" {:move-nodes {:tooltip "M"
:command "v" :command "m"
:fn #(st/emit! (drp/change-edit-mode :move))} :fn #(st/emit! (drp/change-edit-mode :move))}
:draw-nodes {:tooltip "P" :draw-nodes {:tooltip "P"
@ -60,12 +60,12 @@
:command "k" :command "k"
:fn #(st/emit! (drp/separate-nodes))} :fn #(st/emit! (drp/separate-nodes))}
:make-corner {:tooltip "B" :make-corner {:tooltip "X"
:command "b" :command "x"
:fn #(st/emit! (drp/make-corner))} :fn #(st/emit! (drp/make-corner))}
:make-curve {:tooltip (ds/meta "B") :make-curve {:tooltip "C"
:command (ds/c-mod "b") :command "c"
:fn #(st/emit! (drp/make-curve))} :fn #(st/emit! (drp/make-curve))}
:snap-nodes {:tooltip (ds/meta "'") :snap-nodes {:tooltip (ds/meta "'")

View file

@ -8,6 +8,7 @@
(:require (:require
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.dashboard.shortcuts :as sc]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.context :as ctx] [app.main.ui.context :as ctx]
@ -20,6 +21,7 @@
[app.main.ui.dashboard.search :refer [search-page]] [app.main.ui.dashboard.search :refer [search-page]]
[app.main.ui.dashboard.sidebar :refer [sidebar]] [app.main.ui.dashboard.sidebar :refer [sidebar]]
[app.main.ui.dashboard.team :refer [team-settings-page team-members-page]] [app.main.ui.dashboard.team :refer [team-settings-page team-members-page]]
[app.main.ui.hooks :as hooks]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defn ^boolean uuid-str? (defn ^boolean uuid-str?
@ -88,6 +90,8 @@
projects (mf/deref refs/dashboard-projects) projects (mf/deref refs/dashboard-projects)
project (get projects project-id)] project (get projects project-id)]
(hooks/use-shortcuts ::viewer sc/shortcuts)
(mf/use-effect (mf/use-effect
(mf/deps team-id) (mf/deps team-id)
(fn [] (fn []