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

View file

@ -6,6 +6,7 @@
(def workspace (l/key :workspace)) (def workspace (l/key :workspace))
(def workspace-flags (comp workspace (l/key :flags))) (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-shapes (comp workspace (l/key :selected)))
(def selected-page (comp workspace (l/key :page))) (def selected-page (comp workspace (l/key :page)))
(def selected-project (comp workspace (l/key :project))) (def selected-project (comp workspace (l/key :project)))

View file

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