mirror of
https://github.com/penpot/penpot.git
synced 2025-02-13 18:48:37 -05:00
♻️ Refactor toolbar refs and path editing helper
This commit is contained in:
parent
f5dd199bc6
commit
f0955c0e99
3 changed files with 44 additions and 41 deletions
|
@ -6,8 +6,39 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.path.state
|
(ns app.main.data.workspace.path.state
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
|
[app.common.files.helpers :as cph]
|
||||||
[app.common.svg.path.shapes-to-path :as upsp]))
|
[app.common.svg.path.shapes-to-path :as upsp]))
|
||||||
|
|
||||||
|
(defn path-editing?
|
||||||
|
"Returns true if we're editing a path or creating a new one."
|
||||||
|
[state]
|
||||||
|
(let [workspace-local (dm/get-in state [:workspace-local])
|
||||||
|
drawing (dm/get-in state [:workspace-drawing])
|
||||||
|
{:keys [selected edition]} workspace-local
|
||||||
|
edit-path? (dm/get-in workspace-local [:edit-path edition])
|
||||||
|
|
||||||
|
drawing-obj (:object drawing)
|
||||||
|
|
||||||
|
shape (or drawing-obj (-> selected first))
|
||||||
|
shape-id (:id shape)
|
||||||
|
|
||||||
|
single? (= (count selected) 1)
|
||||||
|
editing? (and (some? shape-id) (some? edition) (= shape-id edition))
|
||||||
|
|
||||||
|
;; we need to check if we're drawing a new object
|
||||||
|
;; but we're not using the pencil tool.
|
||||||
|
draw-path? (and (some? drawing-obj)
|
||||||
|
(cph/path-shape? drawing-obj)
|
||||||
|
(not= :curve (:tool drawing)))
|
||||||
|
|
||||||
|
path-edition? (or (and single? editing?
|
||||||
|
(and (not (cph/text-shape? shape))
|
||||||
|
(not (cph/frame-shape? shape))))
|
||||||
|
draw-path?
|
||||||
|
edit-path?)]
|
||||||
|
path-edition?))
|
||||||
|
|
||||||
(defn get-path-id
|
(defn get-path-id
|
||||||
"Retrieves the currently editing path id"
|
"Retrieves the currently editing path id"
|
||||||
[state]
|
[state]
|
||||||
|
|
|
@ -196,46 +196,6 @@
|
||||||
(def context-menu
|
(def context-menu
|
||||||
(l/derived :context-menu workspace-local))
|
(l/derived :context-menu workspace-local))
|
||||||
|
|
||||||
(defn path-editing?
|
|
||||||
"Returns true if we're editing a path or creating a new one."
|
|
||||||
[state]
|
|
||||||
(let [selected (dm/get-in state [:workspace-local :selected])
|
|
||||||
edition (dm/get-in state [:workspace-local :edition])
|
|
||||||
|
|
||||||
edit-path? (dm/get-in state [:workspace-local :edit-path edition])
|
|
||||||
|
|
||||||
drawing (dm/get-in state [:workspace-drawing])
|
|
||||||
drawing-obj (:object drawing)
|
|
||||||
|
|
||||||
shape (or drawing-obj (-> selected first))
|
|
||||||
shape-id (:id shape)
|
|
||||||
|
|
||||||
single? (= (count selected) 1)
|
|
||||||
editing? (and (some? shape-id) (some? edition) (= shape-id edition))
|
|
||||||
|
|
||||||
;; we need to check if we're drawing a new object
|
|
||||||
;; but we're not using the pencil tool.
|
|
||||||
draw-path? (and (some? drawing-obj)
|
|
||||||
(cph/path-shape? drawing-obj)
|
|
||||||
(not= :curve (:tool drawing)))
|
|
||||||
|
|
||||||
path-edition? (or (and single? editing?
|
|
||||||
(and (not (cph/text-shape? shape))
|
|
||||||
(not (cph/frame-shape? shape))))
|
|
||||||
draw-path?
|
|
||||||
edit-path?)]
|
|
||||||
|
|
||||||
path-edition?))
|
|
||||||
|
|
||||||
(def toolbar-hidden
|
|
||||||
(l/derived
|
|
||||||
(fn [state]
|
|
||||||
(let [visibility (dm/get-in state [:workspace-local :hide-toolbar])
|
|
||||||
editing? (path-editing? state)
|
|
||||||
hidden? (if editing? true visibility)]
|
|
||||||
hidden?))
|
|
||||||
st/state))
|
|
||||||
|
|
||||||
;; page item that it is being edited
|
;; page item that it is being edited
|
||||||
(def editing-page-item
|
(def editing-page-item
|
||||||
(l/derived :page-item workspace-local))
|
(l/derived :page-item workspace-local))
|
||||||
|
|
|
@ -7,12 +7,14 @@
|
||||||
(ns app.main.ui.workspace.top-toolbar
|
(ns app.main.ui.workspace.top-toolbar
|
||||||
(:require-macros [app.main.style :as stl])
|
(:require-macros [app.main.style :as stl])
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.media :as cm]
|
[app.common.media :as cm]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
[app.main.data.workspace :as dw]
|
[app.main.data.workspace :as dw]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.main.data.workspace.common :as dwc]
|
||||||
[app.main.data.workspace.media :as dwm]
|
[app.main.data.workspace.media :as dwm]
|
||||||
|
[app.main.data.workspace.path.state :as pst]
|
||||||
[app.main.data.workspace.shortcuts :as sc]
|
[app.main.data.workspace.shortcuts :as sc]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -22,6 +24,7 @@
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.i18n :as i18n :refer [tr]]
|
[app.util.i18n :as i18n :refer [tr]]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
|
[okulary.core :as l]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
(mf/defc image-upload
|
(mf/defc image-upload
|
||||||
|
@ -63,6 +66,15 @@
|
||||||
:ref ref
|
:ref ref
|
||||||
:on-selected on-selected}]]]))
|
:on-selected on-selected}]]]))
|
||||||
|
|
||||||
|
(def toolbar-hidden
|
||||||
|
(l/derived
|
||||||
|
(fn [state]
|
||||||
|
(let [visibility (dm/get-in state [:workspace-local :hide-toolbar])
|
||||||
|
editing? (pst/path-editing? state)
|
||||||
|
hidden? (if editing? true visibility)]
|
||||||
|
hidden?))
|
||||||
|
st/state))
|
||||||
|
|
||||||
(mf/defc top-toolbar
|
(mf/defc top-toolbar
|
||||||
{::mf/wrap [mf/memo]
|
{::mf/wrap [mf/memo]
|
||||||
::mf/wrap-props false}
|
::mf/wrap-props false}
|
||||||
|
@ -73,7 +85,7 @@
|
||||||
read-only? (mf/use-ctx ctx/workspace-read-only?)
|
read-only? (mf/use-ctx ctx/workspace-read-only?)
|
||||||
|
|
||||||
rulers? (mf/deref refs/rulers?)
|
rulers? (mf/deref refs/rulers?)
|
||||||
hide-toolbar? (mf/deref refs/toolbar-hidden)
|
hide-toolbar? (mf/deref toolbar-hidden)
|
||||||
|
|
||||||
interrupt
|
interrupt
|
||||||
(mf/use-fn #(st/emit! :interrupt))
|
(mf/use-fn #(st/emit! :interrupt))
|
||||||
|
|
Loading…
Add table
Reference in a new issue