🚧 Minor reimplementation on how workspace initialization.

This commit is contained in:
Andrey Antukh 2019-11-27 15:33:53 +01:00
parent 59bab376cd
commit 426677935e
8 changed files with 243 additions and 221 deletions

View file

@ -5,7 +5,7 @@
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.main.ui.shapes.group
(:require
#_(:require
[lentes.core :as l]
[rumext.core :as mx]
[uxbox.main.geom :as geom]
@ -24,64 +24,64 @@
;; --- Helpers
(declare group-component)
;; (declare group-component)
(defn- focus-shape
[id]
(-> (l/in [:shapes id])
(l/derive st/state)))
;; (defn- focus-shape
;; [id]
;; (-> (l/in [:shapes id])
;; (l/derive st/state)))
(defn render-component
[shape]
(case (:type shape)
:group (group-component shape)
:text (text/text-component shape)
:icon (icon/icon-component shape)
:rect (rect/rect-component shape)
:path (path/path-component shape)
:image (image/image-component shape)
:circle (circle/circle-component shape)))
;; (defn render-component
;; [shape]
;; (case (:type shape)
;; :group (group-component shape)
;; :text (text/text-component shape)
;; :icon (icon/icon-component shape)
;; :rect (rect/rect-component shape)
;; :path (path/path-component shape)
;; :image (image/image-component shape)
;; :circle (circle/circle-component shape)))
(mx/defc component-container
{:mixins [mx/reactive mx/static]}
[id]
(when-let [shape (mx/react (focus-shape id))]
(when-not (:hidden shape)
(render-component shape))))
;; (mx/defc component-container
;; {:mixins [mx/reactive mx/static]}
;; [id]
;; (when-let [shape (mx/react (focus-shape id))]
;; (when-not (:hidden shape)
;; (render-component shape))))
;; --- Group Component
;; ;; --- Group Component
(declare group-shape)
;; (declare group-shape)
(mx/defc group-component
{:mixins [mx/static mx/reactive]}
[{:keys [id x y width height group] :as shape}]
(let [modifiers (mx/react (refs/selected-modifiers id))
selected (mx/react refs/selected-shapes)
selected? (contains? selected id)
on-mouse-down #(common/on-mouse-down % shape selected)
shape (assoc shape :modifiers modifiers)]
[:g.shape.group-shape
{:class (when selected? "selected")
:on-mouse-down on-mouse-down}
(group-shape shape component-container)]))
;; (mx/defc group-component
;; {:mixins [mx/static mx/reactive]}
;; [{:keys [id x y width height group] :as shape}]
;; (let [modifiers (mx/react (refs/selected-modifiers id))
;; selected (mx/react refs/selected-shapes)
;; selected? (contains? selected id)
;; on-mouse-down #(common/on-mouse-down % shape selected)
;; shape (assoc shape :modifiers modifiers)]
;; [:g.shape.group-shape
;; {:class (when selected? "selected")
;; :on-mouse-down on-mouse-down}
;; (group-shape shape component-container)]))
;; --- Group Shape
;; ;; --- Group Shape
(mx/defc group-shape
{:mixins [mx/static mx/reactive]}
[{:keys [id items modifiers] :as shape} factory]
(let [{:keys [resize displacement]} modifiers
;; (mx/defc group-shape
;; {:mixins [mx/static mx/reactive]}
;; [{:keys [id items modifiers] :as shape} factory]
;; (let [{:keys [resize displacement]} modifiers
xfmt (cond-> (gmt/matrix)
resize (gmt/multiply resize)
displacement (gmt/multiply displacement))
;; xfmt (cond-> (gmt/matrix)
;; resize (gmt/multiply resize)
;; displacement (gmt/multiply displacement))
moving? (boolean displacement)]
[:g {:id (str "shape-" id)
:class (classnames :move-cursor moving?)
:transform (str xfmt)}
(for [item (reverse items)]
(-> (factory item)
(mx/with-key (str item))))]))
;; moving? (boolean displacement)]
;; [:g {:id (str "shape-" id)
;; :class (classnames :move-cursor moving?)
;; :transform (str xfmt)}
;; (for [item (reverse items)]
;; (-> (factory item)
;; (mx/with-key (str item))))]))

View file

@ -2,7 +2,7 @@
;; 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) 2015-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2019 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.ui.workspace.sidebar.sitemap
@ -78,7 +78,8 @@
(mf/defc pages-list
[{:keys [project current-page-id] :as props}]
(let [pages-map (mf/deref pages-map-iref)
pages (map #(get pages-map %) (:pages project))
pages (->> (vals pages-map)
(filter #(= (:project-id %) (:id project))))
deletable? (> (count pages) 1)]
[:ul.element-list
(for [[index item] (map-indexed vector pages)]