0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 00:58:26 -05:00

Minor reorganization on workspace and icons sidebar.

This commit is contained in:
Andrey Antukh 2017-01-09 20:13:43 +01:00
parent 3ea4de7ab5
commit dfa8814887
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 66 additions and 45 deletions

View file

@ -7,14 +7,11 @@
(ns uxbox.main.data.workspace
(:require [cljs.spec :as s]
[beicon.core :as rx]
[uxbox.util.uuid :as uuid]
[uxbox.main.constants :as c]
[potok.core :as ptk]
[uxbox.util.spec :as us]
[uxbox.util.forms :as sc]
[uxbox.util.geom.point :as gpt]
[uxbox.util.workers :as uw]
[lentes.core :as l]
[uxbox.store :as st]
[uxbox.main.constants :as c]
[uxbox.main.lenses :as ul]
[uxbox.main.data.core :refer (worker)]
[uxbox.main.data.projects :as dp]
[uxbox.main.data.pages :as udp]
@ -22,6 +19,11 @@
[uxbox.main.data.shapes-impl :as shimpl]
[uxbox.main.data.lightbox :as udl]
[uxbox.main.data.history :as udh]
[uxbox.util.uuid :as uuid]
[uxbox.util.spec :as us]
[uxbox.util.forms :as sc]
[uxbox.util.geom.point :as gpt]
[uxbox.util.workers :as uw]
[uxbox.util.time :as dt]
[uxbox.util.math :as mth]
[uxbox.util.data :refer (index-of)]))
@ -92,42 +94,55 @@
[project page]
(InitializeWorkspace. project page))
;; --- Toggle Flag
;; --- Select for Drawing
(defn toggle-flag
"Toggle the enabled flag of the specified tool."
[key]
(reify
ptk/UpdateEvent
(update [_ state]
(let [flags (get-in state [:workspace :flags])]
(if (contains? flags key)
(assoc-in state [:workspace :flags] (disj flags key))
(assoc-in state [:workspace :flags] (conj flags key)))))))
(deftype SelectForDrawing [shape]
ptk/UpdateEvent
(update [_ state]
(let [current (l/focus ul/selected-drawing state)]
(if (or (nil? shape)
(= shape current))
(update state :workspace dissoc :drawing)
(assoc-in state [:workspace :drawing] shape)))))
(defn select-for-drawing
"Mark a shape selected for drawing in the canvas."
[shape]
(reify
ptk/UpdateEvent
(update [_ state]
(let [current (get-in state [:workspace :drawing])]
(if (or (nil? shape)
(= shape current))
(update state :workspace dissoc :drawing)
(assoc-in state [:workspace :drawing] shape))))))
(SelectForDrawing. shape))
;; --- Activate Workspace Flag
;; --- Workspace Flags
(defrecord ActivateFlag [flag]
(deftype ActivateFlag [flag]
ptk/UpdateEvent
(update [_ state]
(update-in state [:workspace :flags] conj flag)))
(defn activate-flag
[flag]
{:pre [(keyword? flag)]}
(ActivateFlag. flag))
(deftype DeactivateFlag [flag]
ptk/UpdateEvent
(update [_ state]
(update-in state [:workspace :flags] disj flag)))
(defn deactivate-flag
[flag]
{:pre [(keyword? flag)]}
(DeactivateFlag. flag))
(deftype ToggleFlag [flag]
ptk/WatchEvent
(watch [_ state stream]
(let [flags (get-in state [:workspace :flags])]
(if (contains? flags flag)
(rx/of (deactivate-flag flag))
(rx/of (activate-flag flag))))))
(defn toggle-flag
[flag]
(ToggleFlag. flag))
;; --- Copy to Clipboard
(defrecord CopyToClipboard []

View file

@ -6,6 +6,7 @@
(def workspace (l/key :workspace))
(def workspace-flags (comp workspace (l/key :flags)))
(def selected-drawing (comp workspace (l/key :drawing)))
(def selected-shapes (comp workspace (l/key :selected)))
(def selected-page (comp workspace (l/key :page)))
(def selected-project (comp workspace (l/key :project)))

View file

@ -10,6 +10,7 @@
[uxbox.util.router :as r]
[potok.core :as ptk]
[uxbox.store :as st]
[uxbox.main.lenses :as ul]
[uxbox.main.data.workspace :as dw]
[uxbox.main.data.icons :as udi]
[uxbox.main.ui.shapes.icon :as icon]
@ -22,13 +23,12 @@
;; --- Refs
(def ^:private drawing-shape
(def ^:private drawing-shape-ref
"A focused vision of the drawing property
of the workspace status. This avoids
rerender the whole toolbox on each workspace
change."
(-> (l/in [:workspace :drawing])
(l/derive st/state)))
(l/derive ul/selected-drawing st/state))
;; --- Icons (Component)
@ -52,31 +52,36 @@
(remove-watch local ::key)
own))
(defn- get-first-with-icons
"Get a first collection with icons."
[colls-map]
(->> (vals colls-map)
(sort-by :name)
(filter #(> (:num-icons %) 0))
(first)))
(defn- get-or-select-coll
[local colls-map]
(if (:id @local)
(get colls-map (:id @local))
(let [colls (->> (vals colls-map)
(sort-by :name))
selected-coll (first (filter #(> (:num-icons %) 0) colls))]
(swap! local assoc :id (:id selected-coll)
selected-coll))))
[local colls]
{:pre [(map? colls)]}
(let [selected (:id @local)]
(if selected
(get colls selected)
(let [coll (get-first-with-icons colls)]
(swap! local assoc :id (:d coll))
coll))))
(mx/defcs icons-toolbox
{:mixins [(mx/local) mx/reactive]
:will-mount icons-toolbox-will-mount
:will-unmount icons-toolbox-will-unmount}
[{:keys [rum/local] :as own}]
(let [drawing (mx/react drawing-shape)
(let [drawing (mx/react drawing-shape-ref)
colls-map (mx/react icons/collections-ref)
selected-coll (get-or-select-coll local colls-map)
colls (->> (vals colls-map)
(sort-by :name))
selected-coll (get-or-select-coll local colls-map)
icons (mx/react icons/icons-ref)
icons (->> (vals icons)
icons (->> (vals (mx/react icons/icons-ref))
(filter #(= (:id selected-coll) (:collection %))))]
(letfn [(on-close [event]
(st/emit! (dw/toggle-flag :icons)))
(on-select [icon event]