0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Convert workspace component to use new defc macro.

This commit is contained in:
Andrey Antukh 2017-01-11 18:17:30 +01:00
parent 30ae7a4deb
commit 09b3017874
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -2,13 +2,11 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; 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/. ;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;; ;;
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com> ;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.ui.workspace (ns uxbox.main.ui.workspace
(:require [sablono.core :as html :refer-macros [html]] (:require [beicon.core :as rx]
[rum.core :as rum]
[beicon.core :as rx]
[uxbox.main.constants :as c] [uxbox.main.constants :as c]
[potok.core :as ptk] [potok.core :as ptk]
[uxbox.store :as st] [uxbox.store :as st]
@ -16,10 +14,6 @@
[uxbox.main.data.pages :as udp] [uxbox.main.data.pages :as udp]
[uxbox.main.data.history :as udh] [uxbox.main.data.history :as udh]
[uxbox.main.data.undo :as udu] [uxbox.main.data.undo :as udu]
[uxbox.util.dom :as dom]
[uxbox.util.geom.point :as gpt]
[uxbox.util.data :refer (classnames)]
[uxbox.util.mixins :as mx :include-macros true]
[uxbox.main.ui.messages :as uum] [uxbox.main.ui.messages :as uum]
[uxbox.main.ui.confirm] [uxbox.main.ui.confirm]
[uxbox.main.ui.workspace.images] [uxbox.main.ui.workspace.images]
@ -33,7 +27,11 @@
[uxbox.main.ui.workspace.sidebar.history :refer (history-dialog)] [uxbox.main.ui.workspace.sidebar.history :refer (history-dialog)]
[uxbox.main.ui.workspace.sidebar :refer (left-sidebar right-sidebar)] [uxbox.main.ui.workspace.sidebar :refer (left-sidebar right-sidebar)]
[uxbox.main.ui.workspace.colorpalette :refer (colorpalette)] [uxbox.main.ui.workspace.colorpalette :refer (colorpalette)]
[uxbox.main.ui.workspace.canvas :refer (viewport)])) [uxbox.main.ui.workspace.canvas :refer (viewport)]
[uxbox.util.dom :as dom]
[uxbox.util.geom.point :as gpt]
[uxbox.util.data :refer (classnames)]
[uxbox.util.mixins :as mx :include-macros true]))
;; --- Workspace ;; --- Workspace
@ -99,7 +97,15 @@
(st/emit! (dw/decrease-zoom))) (st/emit! (dw/decrease-zoom)))
(scroll/scroll-to-point dom mouse-point scroll-position)))) (scroll/scroll-to-point dom mouse-point scroll-position))))
(defn- workspace-render (mx/defcs workspace
{:did-remount workspace-did-remount
:will-mount workspace-will-mount
:will-unmount workspace-will-unmount
:did-mount workspace-did-mount
:mixins [mx/static
mx/reactive
shortcuts-mixin
(mx/local)]}
[own] [own]
(let [{:keys [flags zoom page] :as workspace} (mx/react wb/workspace-ref) (let [{:keys [flags zoom page] :as workspace} (mx/react wb/workspace-ref)
left-sidebar? (not (empty? (keep flags [:layers :sitemap left-sidebar? (not (empty? (keep flags [:layers :sitemap
@ -110,47 +116,34 @@
classes (classnames classes (classnames
:no-tool-bar-right (not right-sidebar?) :no-tool-bar-right (not right-sidebar?)
:no-tool-bar-left (not left-sidebar?) :no-tool-bar-left (not left-sidebar?)
:scrolling (:scrolling @local false))] :scrolling (:viewport-positionig workspace))]
(html [:div
[:div (header)
(header) (colorpalette)
(colorpalette) (uum/messages)
(uum/messages)
[:main.main-content [:main.main-content
[:section.workspace-content [:section.workspace-content
{:class classes {:class classes
:on-scroll on-scroll :on-scroll on-scroll
:on-wheel (partial on-wheel own)} :on-wheel (partial on-wheel own)}
(history-dialog page) (history-dialog page)
;; Rules ;; Rules
(horizontal-rule zoom) (horizontal-rule zoom)
(vertical-rule zoom) (vertical-rule zoom)
;; Canvas ;; Canvas
[:section.workspace-canvas [:section.workspace-canvas
{:ref "workspace-canvas"} {:id "workspace-canvas"
(viewport)]] :ref "workspace-canvas"}
(viewport)]]
;; Aside ;; Aside
(when left-sidebar? (when left-sidebar?
(left-sidebar)) (left-sidebar))
(when right-sidebar? (when right-sidebar?
(right-sidebar))]]))) (right-sidebar))]]))
(def workspace
(mx/component
{:render workspace-render
:did-remount workspace-did-remount
:will-mount workspace-will-mount
:will-unmount workspace-will-unmount
:did-mount workspace-did-mount
:name "workspace"
:mixins [mx/static
mx/reactive
shortcuts-mixin
(mx/local)]}))