mirror of
https://github.com/penpot/penpot.git
synced 2025-03-17 10:11:22 -05:00
Move workspace.base refs and streams into separated namespaces.
A first step for streams refactor.
This commit is contained in:
parent
a5554b51cd
commit
8c28a8c0a7
34 changed files with 390 additions and 361 deletions
|
@ -22,12 +22,12 @@
|
|||
[cljsjs/react-dom "15.4.0-0"]
|
||||
[cljsjs/react-dom-server "15.4.0-0"]
|
||||
[cljsjs/moment "2.15.2-3"]
|
||||
[funcool/potok "1.1.0"]
|
||||
[funcool/potok "1.2.0"]
|
||||
[funcool/struct "1.0.0"]
|
||||
[funcool/lentes "1.2.0"]
|
||||
[funcool/beicon "2.8.0"]
|
||||
[funcool/cuerdas "2.0.2"]
|
||||
[funcool/bide "1.2.2"]]
|
||||
[funcool/bide "1.4.0"]]
|
||||
:plugins [[lein-ancient "0.6.10"]]
|
||||
:clean-targets ^{:protect false} ["resources/public/js" "target"]
|
||||
)
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.data.core
|
||||
"Worker related api and initialization events."
|
||||
(:require [beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.workers :as uw]
|
||||
[uxbox.main.constants :as c]))
|
||||
|
||||
;; This excludes webworker instantiation on nodejs where
|
||||
;; the tests are run.
|
||||
|
||||
(when (not= *target* "nodejs")
|
||||
(defonce worker (uw/init "/js/worker.js")))
|
||||
|
|
@ -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-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.data.shapes
|
||||
(:require [cljs.spec :as s :include-macros true]
|
||||
|
@ -13,7 +13,7 @@
|
|||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.lenses :as ul]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.main.data.core :refer (worker)]
|
||||
[uxbox.main.workers :as uwrk]
|
||||
[uxbox.main.data.shapes-impl :as impl]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.util.forms :as sc]
|
||||
|
@ -22,8 +22,7 @@
|
|||
[uxbox.util.geom.matrix :as gmt]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.rlocks :as rlocks]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.util.workers :as uw]))
|
||||
[uxbox.util.uuid :as uuid]))
|
||||
|
||||
;; --- Specs
|
||||
|
||||
|
@ -130,8 +129,6 @@
|
|||
|
||||
;; --- Shape Transformations
|
||||
|
||||
(declare align-point)
|
||||
|
||||
(def ^:private canvas-coords
|
||||
(gpt/point c/canvas-start-x
|
||||
c/canvas-start-y))
|
||||
|
@ -147,7 +144,7 @@
|
|||
(geom/shape->rect-shape state))
|
||||
point1 (gpt/point x1 y1)
|
||||
point2 (gpt/add point1 canvas-coords)]
|
||||
(->> (align-point point2)
|
||||
(->> (uwrk/align-point point2)
|
||||
(rx/map #(gpt/subtract % canvas-coords))
|
||||
(rx/map (fn [{:keys [x y] :as pt}]
|
||||
(apply-temporal-displacement id (gpt/subtract pt point1)))))))))
|
||||
|
@ -551,7 +548,7 @@
|
|||
(let [shape (get-in state [:shapes id])
|
||||
point (get-in shape [:points index])
|
||||
point (gpt/add point canvas-coords)]
|
||||
(->> (align-point point)
|
||||
(->> (uwrk/align-point point)
|
||||
(rx/map #(gpt/subtract % point))
|
||||
(rx/map #(update-path id index %))))))
|
||||
|
||||
|
@ -673,6 +670,7 @@
|
|||
;; --- Move Selected
|
||||
|
||||
(defn alignment-activated?
|
||||
;; TODO: use the function defined in uxbox.main.refs
|
||||
[state]
|
||||
(let [flags (l/focus ul/workspace-flags state)]
|
||||
(and (contains? flags :grid-indexed)
|
||||
|
@ -722,11 +720,3 @@
|
|||
{:pre [(us/valid? ::direction direction)
|
||||
(us/valid? ::speed speed)]}
|
||||
(MoveSelected. direction speed))
|
||||
|
||||
;; --- Point Alignment (with Grid)
|
||||
|
||||
(defn align-point
|
||||
[point]
|
||||
(let [message {:cmd :grid-align :point point}]
|
||||
(->> (uw/ask! worker message)
|
||||
(rx/map :point))))
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.lenses :as ul]
|
||||
[uxbox.main.data.core :refer (worker)]
|
||||
[uxbox.main.workers :as uwrk]
|
||||
[uxbox.main.data.projects :as dp]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
|
@ -20,13 +20,11 @@
|
|||
[uxbox.main.data.shapes-impl :as shimpl]
|
||||
[uxbox.main.data.lightbox :as udl]
|
||||
[uxbox.main.data.history :as udh]
|
||||
|
||||
[uxbox.main.data.workspace.scroll :as wscroll]
|
||||
[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)]))
|
||||
|
@ -282,18 +280,17 @@
|
|||
(watch [_ state stream]
|
||||
(let [page (get-in state [:pages id])
|
||||
opts (:metadata page)
|
||||
message {:cmd :grid-init
|
||||
:width c/viewport-width
|
||||
:height c/viewport-height
|
||||
:x-axis (:grid-x-axis opts c/grid-x-axis)
|
||||
:y-axis (:grid-y-axis opts c/grid-y-axis)}
|
||||
params {:width c/viewport-width
|
||||
:height c/viewport-height
|
||||
:x-axis (:grid-x-axis opts c/grid-x-axis)
|
||||
:y-axis (:grid-y-axis opts c/grid-y-axis)}
|
||||
stoper (->> (rx/filter initialize-alignment? stream)
|
||||
(rx/take 1))]
|
||||
(->> (rx/just nil)
|
||||
(rx/delay 1000)
|
||||
(rx/take-until stoper)
|
||||
(rx/flat-map (fn [_]
|
||||
(rx/merge (->> (uw/send! worker message)
|
||||
(rx/merge (->> (uwrk/initialize-alignment params)
|
||||
(rx/map #(activate-flag :grid-indexed)))
|
||||
(when (:grid-alignment opts)
|
||||
(rx/of (activate-flag :grid-alignment))))))))))
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
are related to UI logic."
|
||||
(:require [beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.rlocks :as rlocks]
|
||||
[uxbox.util.dom :as dom]
|
||||
|
@ -23,9 +23,9 @@
|
|||
[stream]
|
||||
(let [stoper (->> (rx/filter stop-viewport-positioning? stream)
|
||||
(rx/take 1))
|
||||
reference @wb/mouse-viewport-a
|
||||
reference @streams/mouse-viewport-a
|
||||
dom (dom/get-element "workspace-canvas")]
|
||||
(->> wb/mouse-viewport-s
|
||||
(->> streams/mouse-viewport-s
|
||||
(rx/take-until stoper)
|
||||
(rx/map (fn [point]
|
||||
(let [{:keys [x y]} (gpt/subtract point reference)
|
||||
|
|
79
frontend/src/uxbox/main/refs.cljs
Normal file
79
frontend/src/uxbox/main/refs.cljs
Normal file
|
@ -0,0 +1,79 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; 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) 2017 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.refs
|
||||
"A collection of derived refs."
|
||||
(:require [lentes.core :as l]
|
||||
[beicon.core :as rx]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.lenses :as ul]))
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
(defn resolve-project
|
||||
"Retrieve the current project."
|
||||
[state]
|
||||
(let [id (l/focus ul/selected-project state)]
|
||||
(get-in state [:projects id])))
|
||||
|
||||
(defn resolve-page
|
||||
[state]
|
||||
(let [id (l/focus ul/selected-page state)]
|
||||
(get-in state [:pages id])))
|
||||
|
||||
(def workspace
|
||||
(l/derive ul/workspace st/state))
|
||||
|
||||
(def selected-project
|
||||
"Ref to the current selected project."
|
||||
(-> (l/lens resolve-project)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def selected-page
|
||||
"Ref to the current selected page."
|
||||
(-> (l/lens resolve-page)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def selected-page-id
|
||||
"Ref to the current selected page id."
|
||||
(-> (l/key :id)
|
||||
(l/derive selected-page)))
|
||||
|
||||
(def selected-shapes
|
||||
(-> (l/key :selected)
|
||||
(l/derive workspace)))
|
||||
|
||||
(def toolboxes
|
||||
(-> (l/key :toolboxes)
|
||||
(l/derive workspace)))
|
||||
|
||||
(def flags
|
||||
(-> (l/key :flags)
|
||||
(l/derive workspace)))
|
||||
|
||||
(def shapes-by-id
|
||||
(-> (l/key :shapes)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def selected-zoom
|
||||
(-> (l/key :zoom)
|
||||
(l/derive workspace)))
|
||||
|
||||
(defn alignment-activated?
|
||||
[state]
|
||||
(let [flags (l/focus ul/workspace-flags state)]
|
||||
(and (contains? flags :grid-indexed)
|
||||
(contains? flags :grid-alignment)
|
||||
(contains? flags :grid))))
|
||||
|
||||
(def selected-alignment
|
||||
(-> (l/lens alignment-activated?)
|
||||
(l/derive flags)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
82
frontend/src/uxbox/main/streams.cljs
Normal file
82
frontend/src/uxbox/main/streams.cljs
Normal file
|
@ -0,0 +1,82 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; 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) 2017 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.streams
|
||||
"A collection of derived streams."
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.workers :as uwrk]
|
||||
[uxbox.util.geom.point :as gpt]))
|
||||
|
||||
(def page-id-ref-s (rx/from-atom refs/selected-page-id))
|
||||
|
||||
;; --- Scroll Stream
|
||||
|
||||
(defonce scroll-b (rx/subject))
|
||||
|
||||
(defonce scroll-s
|
||||
(as-> scroll-b $
|
||||
(rx/sample 10 $)
|
||||
(rx/merge $ (rx/of (gpt/point)))
|
||||
(rx/dedupe $)))
|
||||
|
||||
(defonce scroll-a
|
||||
(rx/to-atom scroll-s))
|
||||
|
||||
;; --- Events
|
||||
|
||||
(defonce events-b (rx/subject))
|
||||
(defonce events-s (rx/dedupe events-b))
|
||||
|
||||
;; --- Mouse Position Stream
|
||||
|
||||
(defonce mouse-b (rx/subject))
|
||||
(defonce mouse-s (rx/dedupe mouse-b))
|
||||
|
||||
(defonce mouse-canvas-s
|
||||
(->> mouse-s
|
||||
(rx/map :canvas-coords)
|
||||
(rx/share)))
|
||||
|
||||
(defonce mouse-canvas-a
|
||||
(rx/to-atom mouse-canvas-s))
|
||||
|
||||
(defonce mouse-viewport-s
|
||||
(->> mouse-s
|
||||
(rx/map :viewport-coords)
|
||||
(rx/share)))
|
||||
|
||||
(defonce mouse-viewport-a
|
||||
(rx/to-atom mouse-viewport-s))
|
||||
|
||||
(defonce mouse-absolute-s
|
||||
(->> mouse-s
|
||||
(rx/map :window-coords)
|
||||
(rx/share)))
|
||||
|
||||
(defonce mouse-absolute-a
|
||||
(rx/to-atom mouse-absolute-s))
|
||||
|
||||
(defonce mouse-ctrl-s
|
||||
(->> mouse-s
|
||||
(rx/map :ctrl)
|
||||
(rx/share)))
|
||||
|
||||
(defn- coords-delta
|
||||
[[old new]]
|
||||
(gpt/subtract new old))
|
||||
|
||||
(defonce mouse-delta-s
|
||||
(->> mouse-viewport-s
|
||||
(rx/sample 10)
|
||||
(rx/map #(gpt/divide % @refs/selected-zoom))
|
||||
(rx/mapcat (fn [point]
|
||||
(if @refs/selected-alignment
|
||||
(uwrk/align-point point)
|
||||
(rx/of point))))
|
||||
(rx/buffer 2 1)
|
||||
(rx/map coords-delta)
|
||||
(rx/share)))
|
|
@ -9,10 +9,11 @@
|
|||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.keyboard :as kbd]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.rlocks :as rlocks]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
@ -41,14 +42,14 @@
|
|||
(rlocks/release! :shape/move)
|
||||
(st/emit! (uds/apply-displacement shape)))
|
||||
(on-start [shape]
|
||||
(let [stoper (->> (rx/map first wb/events-s)
|
||||
(let [stoper (->> (rx/map first streams/events-s)
|
||||
(rx/filter #(= % :mouse/up))
|
||||
(rx/take 1))
|
||||
stream (->> wb/mouse-delta-s
|
||||
stream (->> streams/mouse-delta-s
|
||||
(rx/take-until stoper))
|
||||
on-move (partial on-move shape)
|
||||
on-stop (partial on-stop shape)]
|
||||
(when @wb/alignment-ref
|
||||
(when @refs/selected-alignment
|
||||
(st/emit! (uds/initial-align-shape shape)))
|
||||
(rx/subscribe stream on-move nil on-stop)))]
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.shapes.selection
|
||||
"Multiple selection handlers component."
|
||||
|
@ -12,8 +12,10 @@
|
|||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.main.workers :as uwrk]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.shapes.common :as scommon]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
|
@ -211,18 +213,18 @@
|
|||
|
||||
(let [shape (->> (geom/shape->rect-shape shape)
|
||||
(geom/size))
|
||||
stoper (->> wb/events-s
|
||||
stoper (->> streams/events-s
|
||||
(rx/map first)
|
||||
(rx/filter #(= % :mouse/up))
|
||||
(rx/take 1))
|
||||
stream (->> wb/mouse-canvas-s
|
||||
(rx/map #(gpt/divide % @wb/zoom-ref))
|
||||
stream (->> streams/mouse-canvas-s
|
||||
(rx/map #(gpt/divide % @refs/selected-zoom))
|
||||
(rx/mapcat (fn [point]
|
||||
(if @wb/alignment-ref
|
||||
(uds/align-point point)
|
||||
(if @refs/selected-alignment
|
||||
(uwrk/align-point point)
|
||||
(rx/of point))))
|
||||
(rx/take-until stoper)
|
||||
(rx/with-latest-from vector wb/mouse-ctrl-s)
|
||||
(rx/with-latest-from vector streams/mouse-ctrl-s)
|
||||
(rx/scan accumulate-width shape)
|
||||
(rx/map (partial calculate-ratio shape)))]
|
||||
(rlocks/acquire! :shape/resize)
|
||||
|
@ -318,13 +320,13 @@
|
|||
(st/emit! (uds/update-path shape-id index delta)))
|
||||
(on-end []
|
||||
(rlocks/release! :shape/resize))]
|
||||
(let [stoper (->> wb/events-s
|
||||
(let [stoper (->> streams/events-s
|
||||
(rx/map first)
|
||||
(rx/filter #(= % :mouse/up))
|
||||
(rx/take 1))
|
||||
stream (rx/take-until stoper wb/mouse-delta-s)]
|
||||
stream (rx/take-until stoper streams/mouse-delta-s)]
|
||||
(rlocks/acquire! :shape/resize)
|
||||
(when @wb/alignment-ref
|
||||
(when @refs/selected-alignment
|
||||
(st/emit! (uds/initial-path-point-align shape-id index)))
|
||||
(rx/subscribe stream on-move nil on-end))))
|
||||
|
||||
|
@ -381,7 +383,7 @@
|
|||
[]
|
||||
(let [shapes (mx/react selected-shapes-ref)
|
||||
edition? (mx/react edition-ref)
|
||||
zoom (mx/react wb/zoom-ref)
|
||||
zoom (mx/react refs/selected-zoom)
|
||||
num (count shapes)
|
||||
{:keys [type] :as shape} (first shapes)]
|
||||
(cond
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
(ns uxbox.main.ui.workspace
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.main.constants :as c]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.main.data.history :as udh]
|
||||
|
@ -20,7 +22,6 @@
|
|||
[uxbox.main.ui.keyboard :as kbd]
|
||||
[uxbox.main.ui.workspace.scroll :as scroll]
|
||||
[uxbox.main.ui.workspace.download]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.workspace.shortcuts :refer (shortcuts-mixin)]
|
||||
[uxbox.main.ui.workspace.header :refer (header)]
|
||||
[uxbox.main.ui.workspace.rules :refer (horizontal-rule vertical-rule)]
|
||||
|
@ -45,9 +46,9 @@
|
|||
[own]
|
||||
(let [[projectid pageid] (:rum/args own)
|
||||
dom (mx/ref-node own "workspace-canvas")
|
||||
scroll-to-page-center #(scroll/scroll-to-page-center dom @wb/page-ref)
|
||||
scroll-to-page-center #(scroll/scroll-to-page-center dom @refs/selected-page)
|
||||
;; sub1 (scroll/watch-scroll-interactions own)
|
||||
sub2 (rx/subscribe wb/page-id-ref-s scroll-to-page-center)]
|
||||
sub2 (rx/subscribe streams/page-id-ref-s scroll-to-page-center)]
|
||||
|
||||
(scroll-to-page-center)
|
||||
|
||||
|
@ -83,15 +84,15 @@
|
|||
(let [target (.-target event)
|
||||
top (.-scrollTop target)
|
||||
left (.-scrollLeft target)]
|
||||
(rx/push! wb/scroll-b (gpt/point left top))))
|
||||
(rx/push! streams/scroll-b (gpt/point left top))))
|
||||
|
||||
(defn- on-wheel
|
||||
[own event]
|
||||
(when (kbd/ctrl? event)
|
||||
(let [prev-zoom @wb/zoom-ref
|
||||
(let [prev-zoom @refs/selected-zoom
|
||||
dom (mx/ref-node own "workspace-canvas")
|
||||
scroll-position (scroll/get-current-position-absolute dom)
|
||||
mouse-point @wb/mouse-viewport-a]
|
||||
mouse-point @streams/mouse-viewport-a]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
(if (pos? (.-deltaY event))
|
||||
|
@ -109,7 +110,7 @@
|
|||
shortcuts-mixin
|
||||
(mx/local)]}
|
||||
[own]
|
||||
(let [{:keys [flags zoom page] :as workspace} (mx/react wb/workspace-ref)
|
||||
(let [{:keys [flags zoom page] :as workspace} (mx/react refs/workspace)
|
||||
left-sidebar? (not (empty? (keep flags [:layers :sitemap
|
||||
:document-history])))
|
||||
right-sidebar? (not (empty? (keep flags [:icons :drawtools
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.base
|
||||
(:require [beicon.core :as rx]
|
||||
[lentes.core :as l]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.lenses :as ul]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[goog.events :as events])
|
||||
(:import goog.events.EventType))
|
||||
|
||||
;; FIXME: split this namespace in two:
|
||||
;; uxbox.main.ui.streams and uxbox.main.ui.workspace.refs
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
(defn resolve-project
|
||||
"Retrieve the current project."
|
||||
[state]
|
||||
(let [id (l/focus ul/selected-project state)]
|
||||
(get-in state [:projects id])))
|
||||
|
||||
(defn resolve-page
|
||||
[state]
|
||||
(let [id (l/focus ul/selected-page state)]
|
||||
(get-in state [:pages id])))
|
||||
|
||||
;; --- Refs
|
||||
|
||||
(def workspace-ref (l/derive ul/workspace st/state))
|
||||
|
||||
(def project-ref
|
||||
"Ref to the current selected project."
|
||||
(-> (l/lens resolve-project)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def page-ref
|
||||
"Ref to the current selected page."
|
||||
(-> (l/lens resolve-page)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def page-id-ref
|
||||
"Ref to the current selected page id."
|
||||
(-> (l/key :id)
|
||||
(l/derive page-ref)))
|
||||
|
||||
(def page-id-ref-s (rx/from-atom page-id-ref))
|
||||
|
||||
(def selected-shapes-ref
|
||||
(-> (l/key :selected)
|
||||
(l/derive workspace-ref)))
|
||||
|
||||
(def toolboxes-ref
|
||||
(-> (l/key :toolboxes)
|
||||
(l/derive workspace-ref)))
|
||||
|
||||
(def flags-ref
|
||||
(-> (l/key :flags)
|
||||
(l/derive workspace-ref)))
|
||||
|
||||
(def shapes-by-id-ref
|
||||
(-> (l/key :shapes)
|
||||
(l/derive st/state)))
|
||||
|
||||
(def zoom-ref
|
||||
(-> (l/key :zoom)
|
||||
(l/derive workspace-ref)))
|
||||
|
||||
(def zoom-ref-s (rx/from-atom zoom-ref))
|
||||
|
||||
(def alignment-ref
|
||||
(-> (l/lens uds/alignment-activated?)
|
||||
(l/derive flags-ref)))
|
||||
|
||||
;; --- Scroll Stream
|
||||
|
||||
(defonce scroll-b (rx/subject))
|
||||
|
||||
(defonce scroll-s
|
||||
(as-> scroll-b $
|
||||
(rx/sample 10 $)
|
||||
(rx/merge $ (rx/of (gpt/point)))
|
||||
(rx/dedupe $)))
|
||||
|
||||
(defonce scroll-a
|
||||
(rx/to-atom scroll-s))
|
||||
|
||||
;; --- Events
|
||||
|
||||
(defonce events-b (rx/subject))
|
||||
(defonce events-s (rx/dedupe events-b))
|
||||
|
||||
;; --- Mouse Position Stream
|
||||
|
||||
(defonce mouse-b (rx/subject))
|
||||
(defonce mouse-s (rx/dedupe mouse-b))
|
||||
|
||||
(defonce mouse-canvas-s
|
||||
(->> mouse-s
|
||||
(rx/map :canvas-coords)
|
||||
(rx/share)))
|
||||
|
||||
(defonce mouse-canvas-a
|
||||
(rx/to-atom mouse-canvas-s))
|
||||
|
||||
(defonce mouse-viewport-s
|
||||
(->> mouse-s
|
||||
(rx/map :viewport-coords)
|
||||
(rx/share)))
|
||||
|
||||
(defonce mouse-viewport-a
|
||||
(rx/to-atom mouse-viewport-s))
|
||||
|
||||
(defonce mouse-absolute-s
|
||||
(->> mouse-s
|
||||
(rx/map :window-coords)
|
||||
(rx/share)))
|
||||
|
||||
(defonce mouse-absolute-a
|
||||
(rx/to-atom mouse-absolute-s))
|
||||
|
||||
(defonce mouse-ctrl-s
|
||||
(->> mouse-s
|
||||
(rx/map :ctrl)
|
||||
(rx/share)))
|
||||
|
||||
(defn- coords-delta
|
||||
[[old new]]
|
||||
(gpt/subtract new old))
|
||||
|
||||
(defonce mouse-delta-s
|
||||
(->> mouse-viewport-s
|
||||
(rx/sample 10)
|
||||
(rx/map #(gpt/divide % @zoom-ref))
|
||||
(rx/mapcat (fn [point]
|
||||
(if @alignment-ref
|
||||
(uds/align-point point)
|
||||
(rx/of point))))
|
||||
(rx/buffer 2 1)
|
||||
(rx/map coords-delta)
|
||||
(rx/share)))
|
|
@ -12,13 +12,14 @@
|
|||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.main.data.projects :as dp]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.keyboard :as kbd]
|
||||
[uxbox.main.ui.shapes :as uus]
|
||||
[uxbox.main.ui.shapes.selection :refer (selection-handlers)]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.workspace.scroll :as scroll]
|
||||
[uxbox.main.ui.workspace.drawarea :refer (draw-area)]
|
||||
[uxbox.main.ui.workspace.ruler :refer (ruler)]
|
||||
|
@ -47,8 +48,8 @@
|
|||
(mx/defc coordinates
|
||||
{:mixins [mx/reactive mx/static]}
|
||||
[]
|
||||
(let [zoom (mx/react wb/zoom-ref)
|
||||
coords (some-> (mx/react wb/mouse-canvas-a)
|
||||
(let [zoom (mx/react refs/selected-zoom)
|
||||
coords (some-> (mx/react streams/mouse-canvas-a)
|
||||
(gpt/divide zoom)
|
||||
(gpt/round 0))]
|
||||
[:ul.coordinates
|
||||
|
@ -74,7 +75,7 @@
|
|||
(mx/defc cursor-tooltip
|
||||
{:mixins [mx/reactive mx/static]}
|
||||
[tooltip]
|
||||
(let [coords (mx/react wb/mouse-absolute-a)]
|
||||
(let [coords (mx/react streams/mouse-absolute-a)]
|
||||
[:span.cursor-tooltip
|
||||
{:style
|
||||
{:position "fixed"
|
||||
|
@ -87,7 +88,7 @@
|
|||
(mx/defc canvas
|
||||
{:mixins [mx/reactive]}
|
||||
[{:keys [metadata id] :as page}]
|
||||
(let [workspace (mx/react wb/workspace-ref)
|
||||
(let [workspace (mx/react refs/workspace)
|
||||
flags (:flags workspace)
|
||||
width (:width metadata)
|
||||
height (:height metadata)]
|
||||
|
@ -131,7 +132,7 @@
|
|||
(let [opts {:key (.-keyCode event)
|
||||
:shift? (kbd/shift? event)
|
||||
:ctrl? (kbd/ctrl? event)}]
|
||||
(rx/push! wb/events-b [:key/down opts])
|
||||
(rx/push! streams/events-b [:key/down opts])
|
||||
(when (kbd/space? event)
|
||||
(st/emit! (dw/start-viewport-positioning)))))
|
||||
#_(rlocks/acquire! :workspace/scroll)
|
||||
|
@ -142,7 +143,7 @@
|
|||
:ctrl? (kbd/ctrl? event)}]
|
||||
(when (kbd/space? event)
|
||||
(st/emit! (dw/stop-viewport-positioning)))
|
||||
(rx/push! wb/events-b [:key/up opts])))
|
||||
(rx/push! streams/events-b [:key/up opts])))
|
||||
|
||||
(on-mousemove [event]
|
||||
(let [wpt (gpt/point (.-clientX event)
|
||||
|
@ -154,10 +155,10 @@
|
|||
:window-coords wpt
|
||||
:viewport-coords vppt
|
||||
:canvas-coords cvpt}]
|
||||
;; FIXME: refactor streams in order to use the wb/events-b
|
||||
;; FIXME: refactor streams in order to use the streams/events-b
|
||||
;; for all keyboard and mouse events and then derive
|
||||
;; all the other from it.
|
||||
(rx/push! wb/mouse-b event)))]
|
||||
(rx/push! streams/mouse-b event)))]
|
||||
|
||||
(let [key1 (events/listen js/document EventType.MOUSEMOVE on-mousemove)
|
||||
key2 (events/listen js/document EventType.KEYDOWN on-key-down)
|
||||
|
@ -179,8 +180,8 @@
|
|||
:will-unmount viewport-will-unmount
|
||||
:mixins [mx/reactive]}
|
||||
[]
|
||||
(let [workspace (mx/react wb/workspace-ref)
|
||||
page (mx/react wb/page-ref)
|
||||
(let [workspace (mx/react refs/workspace)
|
||||
page (mx/react refs/selected-page)
|
||||
flags (:flags workspace)
|
||||
drawing? (:drawing workspace)
|
||||
tooltip (if (:tooltip workspace)
|
||||
|
@ -191,7 +192,7 @@
|
|||
(dom/stop-propagation event)
|
||||
(let [opts {:shift? (kbd/shift? event)
|
||||
:ctrl? (kbd/ctrl? event)}]
|
||||
(rx/push! wb/events-b [:mouse/down opts]))
|
||||
(rx/push! streams/events-b [:mouse/down opts]))
|
||||
(if (:drawing workspace)
|
||||
(rlocks/acquire! :ui/draw)
|
||||
(do
|
||||
|
@ -203,22 +204,22 @@
|
|||
(dom/stop-propagation event)
|
||||
(let [opts {:shift? (kbd/shift? event)
|
||||
:ctrl? (kbd/ctrl? event)}]
|
||||
(rx/push! wb/events-b [:mouse/right-click opts])))
|
||||
(rx/push! streams/events-b [:mouse/right-click opts])))
|
||||
(on-mouse-up [event]
|
||||
(dom/stop-propagation event)
|
||||
(let [opts {:shift? (kbd/shift? event)
|
||||
:ctrl? (kbd/ctrl? event)}]
|
||||
(rx/push! wb/events-b [:mouse/up])))
|
||||
(rx/push! streams/events-b [:mouse/up])))
|
||||
(on-click [event]
|
||||
(dom/stop-propagation event)
|
||||
(let [opts {:shift? (kbd/shift? event)
|
||||
:ctrl? (kbd/ctrl? event)}]
|
||||
(rx/push! wb/events-b [:mouse/click opts])))
|
||||
(rx/push! streams/events-b [:mouse/click opts])))
|
||||
(on-double-click [event]
|
||||
(dom/stop-propagation event)
|
||||
(let [opts {:shift? (kbd/shift? event)
|
||||
:ctrl? (kbd/ctrl? event)}]
|
||||
(rx/push! wb/events-b [:mouse/double-click opts])))]
|
||||
(rx/push! streams/events-b [:mouse/double-click opts])))]
|
||||
[:div
|
||||
(coordinates)
|
||||
(when tooltip
|
||||
|
|
|
@ -2,21 +2,21 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.colorpalette
|
||||
(:require [beicon.core :as rx]
|
||||
[lentes.core :as l]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.data.colors :as dc]
|
||||
[uxbox.main.ui.dashboard.colors :refer (collections-ref)]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.keyboard :as kbd]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.lens :as ul]
|
||||
[uxbox.util.data :refer (read-string)]
|
||||
[uxbox.util.color :refer (hex->rgb)]
|
||||
|
@ -115,6 +115,6 @@
|
|||
{:mixins [mx/static mx/reactive]
|
||||
:will-mount colorpalette-will-mount}
|
||||
[]
|
||||
(let [flags (mx/react wb/flags-ref)]
|
||||
(let [flags (mx/react refs/flags)]
|
||||
(when (contains? flags :colorpalette)
|
||||
(palette))))
|
||||
|
|
|
@ -2,24 +2,23 @@
|
|||
;; 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) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2016-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.colorpicker
|
||||
(:require [lentes.core :as l]
|
||||
[uxbox.util.router :as rt]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.lightbox :as lbx]
|
||||
[uxbox.main.ui.colorpicker :as cp]
|
||||
[uxbox.main.ui.workspace.recent-colors :refer [recent-colors]]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.util.router :as rt]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.data :refer [parse-int parse-float read-string]]))
|
||||
|
@ -50,7 +49,7 @@
|
|||
(mx/defcs page-colorpicker
|
||||
{:mixins [mx/reactive mx/static]}
|
||||
[own {:keys [x y attr default] :as opts}]
|
||||
(let [{:keys [id metadata] :as page} (mx/react wb/page-ref)]
|
||||
(let [{:keys [id metadata] :as page} (mx/react refs/selected-page)]
|
||||
(letfn [(change-color [color]
|
||||
(let [metadata (assoc metadata attr color)]
|
||||
(st/emit! (udp/update-metadata id metadata))))]
|
||||
|
|
|
@ -8,20 +8,20 @@
|
|||
(ns uxbox.main.ui.workspace.download
|
||||
(:require [cuerdas.core :as str]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[lentes.core :as l]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.lightbox :as udl]
|
||||
[uxbox.main.exports :as exports]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.lightbox :as lbx]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.util.blob :as blob]
|
||||
[uxbox.util.data :refer (read-string)]
|
||||
[uxbox.util.time :as dt]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.zip :as zip]
|
||||
[lentes.core :as l]))
|
||||
[uxbox.util.zip :as zip]))
|
||||
|
||||
;; --- Refs
|
||||
|
||||
|
@ -92,7 +92,7 @@
|
|||
(mx/defcs download-dialog
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[own]
|
||||
(let [project (mx/react wb/project-ref)
|
||||
(let [project (mx/react refs/selected-project)
|
||||
pages (mx/react pages-ref)
|
||||
current (mx/react current-page-ref)]
|
||||
(letfn [(on-close [event]
|
||||
|
|
|
@ -2,8 +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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.ui.workspace.drawarea
|
||||
"Draw interaction and component."
|
||||
|
@ -13,10 +12,12 @@
|
|||
[uxbox.util.rlocks :as rlocks]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.main.workers :as uwrk]
|
||||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.shapes :as shapes]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.geom.path :as path]
|
||||
|
@ -114,7 +115,7 @@
|
|||
"Function execution when draw shape operation is requested.
|
||||
This is a entry point for the draw interaction."
|
||||
[]
|
||||
(when-let [shape (:drawing @wb/workspace-ref)]
|
||||
(when-let [shape (:drawing @refs/workspace)]
|
||||
(case (:type shape)
|
||||
:icon (on-init-draw-icon shape)
|
||||
:image (on-init-draw-icon shape)
|
||||
|
@ -127,7 +128,7 @@
|
|||
|
||||
(defn- on-init-draw-icon
|
||||
[{:keys [metadata] :as shape}]
|
||||
(let [{:keys [x y]} (gpt/divide @wb/mouse-canvas-a @wb/zoom-ref)
|
||||
(let [{:keys [x y]} (gpt/divide @streams/mouse-canvas-a @refs/selected-zoom)
|
||||
{:keys [width height]} metadata
|
||||
proportion (/ width height)
|
||||
props {:x1 x
|
||||
|
@ -159,7 +160,7 @@
|
|||
|
||||
(defn- translate-to-canvas
|
||||
[point]
|
||||
(let [zoom @wb/zoom-ref
|
||||
(let [zoom @refs/selected-zoom
|
||||
ccords (gpt/multiply canvas-coords zoom)]
|
||||
(-> point
|
||||
(gpt/subtract ccords)
|
||||
|
@ -167,8 +168,8 @@
|
|||
|
||||
(defn- conditional-align
|
||||
[point]
|
||||
(if @wb/alignment-ref
|
||||
(uds/align-point point)
|
||||
(if @refs/selected-alignment
|
||||
(uwrk/align-point point)
|
||||
(rx/of point)))
|
||||
|
||||
(defn- on-init-draw-path
|
||||
|
@ -184,18 +185,18 @@
|
|||
(and (= type :mouse/click)
|
||||
(false? (:shift? opts))))]
|
||||
|
||||
(let [mouse (->> (rx/sample 10 wb/mouse-viewport-s)
|
||||
(let [mouse (->> (rx/sample 10 streams/mouse-viewport-s)
|
||||
(rx/mapcat conditional-align)
|
||||
(rx/map translate-to-canvas))
|
||||
stoper (->> (rx/merge
|
||||
(rx/take 1 drawing-stoper)
|
||||
(rx/filter stoper-event? wb/events-s))
|
||||
(rx/filter stoper-event? streams/events-s))
|
||||
(rx/take 1))
|
||||
firstpos (rx/take 1 mouse)
|
||||
stream (->> (rx/take-until stoper mouse)
|
||||
(rx/skip-while #(nil? @drawing-shape))
|
||||
(rx/with-latest-from vector wb/mouse-ctrl-s))
|
||||
ptstream (->> (rx/take-until stoper wb/events-s)
|
||||
(rx/with-latest-from vector streams/mouse-ctrl-s))
|
||||
ptstream (->> (rx/take-until stoper streams/events-s)
|
||||
(rx/filter new-point-event?)
|
||||
(rx/with-latest-from vector mouse)
|
||||
(rx/map second))
|
||||
|
@ -252,10 +253,10 @@
|
|||
|
||||
(defn- on-init-draw-free-path
|
||||
[shape]
|
||||
(let [mouse (->> (rx/sample 10 wb/mouse-viewport-s)
|
||||
(let [mouse (->> (rx/sample 10 streams/mouse-viewport-s)
|
||||
(rx/mapcat conditional-align)
|
||||
(rx/map translate-to-canvas))
|
||||
stoper (->> wb/events-s
|
||||
stoper (->> streams/events-s
|
||||
(rx/map first)
|
||||
(rx/filter #(= % :mouse/up))
|
||||
(rx/take 1))
|
||||
|
@ -286,17 +287,17 @@
|
|||
|
||||
(defn- on-init-draw-generic
|
||||
[shape]
|
||||
(let [mouse (->> wb/mouse-viewport-s
|
||||
(let [mouse (->> streams/mouse-viewport-s
|
||||
(rx/mapcat conditional-align)
|
||||
(rx/map translate-to-canvas))
|
||||
stoper (->> wb/events-s
|
||||
stoper (->> streams/events-s
|
||||
(rx/map first)
|
||||
(rx/filter #(= % :mouse/up))
|
||||
(rx/take 1))
|
||||
firstpos (rx/take 1 mouse)
|
||||
stream (->> (rx/take-until stoper mouse)
|
||||
(rx/skip-while #(nil? @drawing-shape))
|
||||
(rx/with-latest-from vector wb/mouse-ctrl-s))]
|
||||
(rx/with-latest-from vector streams/mouse-ctrl-s))]
|
||||
|
||||
(letfn [(on-start [{:keys [x y] :as pt}]
|
||||
(let [shape (geom/setup shape {:x1 x :y1 y :x2 x :y2 y})]
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.grid
|
||||
(:require [cuerdas.core :as str]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.main.ui.workspace.base :as wb]))
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.util.mixins :as mx :include-macros true]))
|
||||
|
||||
;; --- Grid (Component)
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
|||
(mx/defcs grid
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[own]
|
||||
(let [options (:metadata (mx/react wb/page-ref))
|
||||
(let [options (:metadata (mx/react refs/selected-page))
|
||||
color (:grid-color options "#cccccc")
|
||||
width c/viewport-width
|
||||
height c/viewport-height
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.header
|
||||
(:require [beicon.core :as rx]
|
||||
|
@ -11,11 +11,11 @@
|
|||
[uxbox.util.router :as r]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.history :as udh]
|
||||
[uxbox.main.data.lightbox :as udl]
|
||||
[uxbox.main.ui.workspace.clipboard]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.users :as ui.u]
|
||||
[uxbox.main.ui.navigation :as nav]
|
||||
|
@ -28,7 +28,7 @@
|
|||
(mx/defc zoom-widget
|
||||
{:mixins [mx/reactive mx/static]}
|
||||
[]
|
||||
(let [zoom (mx/react wb/zoom-ref)
|
||||
(let [zoom (mx/react refs/selected-zoom)
|
||||
increase #(st/emit! (dw/increase-zoom))
|
||||
decrease #(st/emit! (dw/decrease-zoom))]
|
||||
[:ul.options-view
|
||||
|
@ -49,9 +49,9 @@
|
|||
(mx/defc header
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[]
|
||||
(let [project (mx/react wb/project-ref)
|
||||
page (mx/react wb/page-ref)
|
||||
flags (mx/react wb/flags-ref)
|
||||
(let [project (mx/react refs/selected-project)
|
||||
page (mx/react refs/selected-page)
|
||||
flags (mx/react refs/flags)
|
||||
toggle #(st/emit! (dw/toggle-flag %))
|
||||
on-undo #(st/emit! (udh/backwards-to-previous-version))
|
||||
on-redo #(st/emit! (udh/forward-to-next-version))
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.recent-colors
|
||||
(:require [lentes.core :as l]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.dom :as dom]
|
||||
|
@ -39,7 +39,7 @@
|
|||
(mx/defc recent-colors
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[{:keys [page id] :as shape} callback]
|
||||
(let [shapes-by-id (mx/react wb/shapes-by-id-ref)
|
||||
(let [shapes-by-id (mx/react refs/shapes-by-id)
|
||||
shapes (->> (vals shapes-by-id)
|
||||
(filter #(= (:page %) page)))
|
||||
colors (calculate-colors shapes)]
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
(ns uxbox.main.ui.workspace.ruler
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[rum.core :as rum]
|
||||
[potok.core :as ptk]
|
||||
[beicon.core :as rx]
|
||||
[uxbox.main.constants :as c]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.util.math :as mth]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
@ -74,10 +75,10 @@
|
|||
(on-value-aligned pos)
|
||||
(on-value-simple pos)))]
|
||||
|
||||
(let [stream (->> wb/mouse-absolute-s
|
||||
(let [stream (->> streams/mouse-absolute-s
|
||||
(rx/filter #(:active @local))
|
||||
(rx/map #(resolve-position own %))
|
||||
(rx/with-latest-from vector wb/mouse-ctrl-s))
|
||||
(rx/with-latest-from vector streams/mouse-ctrl-s))
|
||||
sub (rx/on-value stream on-value)]
|
||||
(assoc own ::sub sub))))
|
||||
|
||||
|
@ -116,8 +117,8 @@
|
|||
(defn- overlay-line-render
|
||||
[own center pt]
|
||||
(let [distance (-> (gpt/distance
|
||||
(gpt/divide pt @wb/zoom-ref)
|
||||
(gpt/divide center @wb/zoom-ref))
|
||||
(gpt/divide pt @refs/selected-zoom)
|
||||
(gpt/divide center @refs/selected-zoom))
|
||||
(mth/precision 4))
|
||||
angle (-> (gpt/angle pt center)
|
||||
(mth/precision 4))
|
||||
|
@ -139,7 +140,7 @@
|
|||
|
||||
(defn- ruler-render
|
||||
[own]
|
||||
(let [flags (mx/react wb/flags-ref)]
|
||||
(let [flags (mx/react refs/flags)]
|
||||
(when (contains? flags :ruler)
|
||||
(overlay))))
|
||||
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.rules
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[rum.core :as rum]
|
||||
[cuerdas.core :as str]
|
||||
[beicon.core :as rx]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.store :as s]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.util.mixins :as mx :include-macros true]))
|
||||
|
||||
;; --- Constants & Helpers
|
||||
|
@ -144,7 +144,7 @@
|
|||
|
||||
(defn horizontal-rule-render
|
||||
[own zoom]
|
||||
(let [scroll (mx/react wb/scroll-a)
|
||||
(let [scroll (mx/react streams/scroll-a)
|
||||
scroll-x (:x scroll)
|
||||
translate-x (- (- c/canvas-scroll-padding) (:x scroll))]
|
||||
(html
|
||||
|
@ -164,7 +164,7 @@
|
|||
|
||||
(defn vertical-rule-render
|
||||
[own zoom]
|
||||
(let [scroll (mx/react wb/scroll-a)
|
||||
(let [scroll (mx/react streams/scroll-a)
|
||||
scroll-y (:y scroll)
|
||||
translate-y (- (- c/canvas-scroll-padding) (:y scroll))]
|
||||
(html
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"Workspace scroll events handling."
|
||||
(:require [beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.rlocks :as rlocks]
|
||||
[uxbox.util.dom :as dom]
|
||||
|
@ -24,8 +24,8 @@
|
|||
[dom center]
|
||||
(let [viewport-width (.-offsetWidth dom)
|
||||
viewport-height (.-offsetHeight dom)
|
||||
position-x (- (* (:x center) @wb/zoom-ref) (/ viewport-width 2))
|
||||
position-y (- (* (:y center) @wb/zoom-ref) (/ viewport-height 2))
|
||||
position-x (- (* (:x center) @refs/selected-zoom) (/ viewport-width 2))
|
||||
position-y (- (* (:y center) @refs/selected-zoom) (/ viewport-height 2))
|
||||
position (gpt/point position-x position-y)]
|
||||
(set-scroll-position dom position)))
|
||||
|
||||
|
@ -48,7 +48,7 @@
|
|||
|
||||
(defn get-current-center-absolute
|
||||
[dom]
|
||||
(gpt/divide (get-current-center dom) @wb/zoom-ref))
|
||||
(gpt/divide (get-current-center dom) @refs/selected-zoom))
|
||||
|
||||
(defn get-current-position
|
||||
[dom]
|
||||
|
@ -58,10 +58,10 @@
|
|||
|
||||
(defn get-current-position-absolute
|
||||
[dom]
|
||||
(gpt/divide (get-current-position dom) @wb/zoom-ref))
|
||||
(gpt/divide (get-current-position dom) @refs/selected-zoom))
|
||||
|
||||
(defn scroll-to-point
|
||||
[dom point position]
|
||||
(let [viewport-offset (gpt/subtract point position)
|
||||
new-scroll-position (gpt/subtract (gpt/multiply point @wb/zoom-ref) (gpt/multiply viewport-offset @wb/zoom-ref))]
|
||||
new-scroll-position (gpt/subtract (gpt/multiply point @refs/selected-zoom) (gpt/multiply viewport-offset @refs/selected-zoom))]
|
||||
(set-scroll-position dom new-scroll-position)))
|
||||
|
|
|
@ -2,20 +2,21 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.selrect
|
||||
"Mouse selection interaction and component."
|
||||
(:require [beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.streams :as streams]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.rlocks :as rlocks]))
|
||||
|
||||
(defonce position (atom nil))
|
||||
|
@ -64,7 +65,7 @@
|
|||
(defn- translate-to-canvas
|
||||
"Translate the given rect to the canvas coordinates system."
|
||||
[rect]
|
||||
(let [zoom @wb/zoom-ref
|
||||
(let [zoom @refs/selected-zoom
|
||||
startx (* c/canvas-start-x zoom)
|
||||
starty (* c/canvas-start-y zoom)]
|
||||
(assoc rect
|
||||
|
@ -101,11 +102,11 @@
|
|||
(defn- on-start
|
||||
"Function execution when selrect action is started."
|
||||
[]
|
||||
(let [stoper (->> wb/events-s
|
||||
(let [stoper (->> streams/events-s
|
||||
(rx/map first)
|
||||
(rx/filter #(= % :mouse/up))
|
||||
(rx/take 1))
|
||||
stream (rx/take-until stoper wb/mouse-viewport-s)
|
||||
pos @wb/mouse-viewport-a]
|
||||
stream (rx/take-until stoper streams/mouse-viewport-s)
|
||||
pos @streams/mouse-viewport-a]
|
||||
(reset! position {:start pos :current pos})
|
||||
(rx/subscribe stream on-move nil on-complete)))
|
||||
|
|
|
@ -2,29 +2,29 @@
|
|||
;; 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-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2017 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.main.ui.workspace.sidebar
|
||||
(:require [lentes.core :as l]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.util.router :as r]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.ui.workspace.sidebar.options :refer (options-toolbox)]
|
||||
[uxbox.main.ui.workspace.sidebar.layers :refer (layers-toolbox)]
|
||||
[uxbox.main.ui.workspace.sidebar.sitemap :refer (sitemap-toolbox)]
|
||||
[uxbox.main.ui.workspace.sidebar.history :refer (history-toolbox)]
|
||||
[uxbox.main.ui.workspace.sidebar.icons :refer (icons-toolbox)]
|
||||
[uxbox.main.ui.workspace.sidebar.drawtools :refer (draw-toolbox)]))
|
||||
[uxbox.main.ui.workspace.sidebar.drawtools :refer (draw-toolbox)]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.mixins :as mx :include-macros true]))
|
||||
|
||||
;; --- Left Sidebar (Component)
|
||||
|
||||
(mx/defc left-sidebar
|
||||
{:mixins [mx/reactive mx/static]}
|
||||
[]
|
||||
(let [flags (mx/react wb/flags-ref)]
|
||||
(let [flags (mx/react refs/flags)]
|
||||
[:aside#settings-bar.settings-bar.settings-bar-left
|
||||
[:div.settings-bar-inside
|
||||
(when (contains? flags :sitemap)
|
||||
|
@ -39,7 +39,7 @@
|
|||
(mx/defc right-sidebar
|
||||
{:mixins [mx/reactive mx/static]}
|
||||
[]
|
||||
(let [flags (mx/react wb/flags-ref)]
|
||||
(let [flags (mx/react refs/flags)]
|
||||
[:aside#settings-bar.settings-bar
|
||||
[:div.settings-bar-inside
|
||||
(when (contains? flags :drawtools)
|
||||
|
|
|
@ -8,16 +8,16 @@
|
|||
(ns uxbox.main.ui.workspace.sidebar.drawtools
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[lentes.core :as l]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.data :refer (read-string)]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]))
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
;; --- Refs
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
|||
(mx/defc draw-toolbox
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[own]
|
||||
(let [workspace (mx/react wb/workspace-ref)
|
||||
(let [workspace (mx/react refs/workspace)
|
||||
drawing (mx/react drawing-shape)
|
||||
close #(st/emit! (dw/toggle-flag :drawtools))
|
||||
tools (->> (into [] +draw-tools+)
|
||||
|
|
|
@ -9,16 +9,16 @@
|
|||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[rum.core :as rum]
|
||||
[lentes.core :as l]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.main.data.history :as udh]
|
||||
[uxbox.main.data.messages :as udm]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.time :as dt]
|
||||
[uxbox.util.data :refer (read-string)]
|
||||
|
@ -118,7 +118,7 @@
|
|||
(defn history-toolbox-render
|
||||
[own]
|
||||
(let [local (:rum/local own)
|
||||
page (mx/react wb/page-ref)
|
||||
page (mx/react refs/selected-page)
|
||||
history (mx/react history-ref)
|
||||
section (:section @local :main)
|
||||
close #(st/emit! (dw/toggle-flag :document-history))
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.icons :as udi]
|
||||
[uxbox.main.ui.shapes.icon :as icon]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.dashboard.icons :as icons]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
|
|
|
@ -9,16 +9,16 @@
|
|||
(:require [lentes.core :as l]
|
||||
[cuerdas.core :as str]
|
||||
[goog.events :as events]
|
||||
[uxbox.util.router :as r]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.util.data :refer (read-string classnames)]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.shapes.icon :as icon]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.keyboard :as kbd]
|
||||
[uxbox.util.data :refer (read-string classnames)]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.dom.dnd :as dnd]
|
||||
[uxbox.util.dom :as dom])
|
||||
|
@ -201,7 +201,7 @@
|
|||
(let [local (:rum/local own)
|
||||
selected? (contains? selected (:id item))
|
||||
collapsed? (:collapsed item true)
|
||||
shapes-map (mx/react wb/shapes-by-id-ref)
|
||||
shapes-map (mx/react refs/shapes-by-id)
|
||||
classes (classnames
|
||||
:selected selected?
|
||||
:drag-top (= :top (:over @local))
|
||||
|
@ -290,9 +290,10 @@
|
|||
(mx/defc layers-toolbox
|
||||
{:mixins [mx/reactive]}
|
||||
[]
|
||||
(let [workspace (mx/react wb/workspace-ref)
|
||||
(let [workspace (mx/react refs/workspace)
|
||||
selected (:selected workspace)
|
||||
shapes-map (mx/react wb/shapes-by-id-ref)
|
||||
;; TODO: dont react to the while shapes-by-id
|
||||
shapes-map (mx/react refs/shapes-by-id)
|
||||
page (mx/react (focus-page (:page workspace)))
|
||||
close #(st/emit! (udw/toggle-flag :layers))
|
||||
duplicate #(st/emit! (uds/duplicate-selected))
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
[uxbox.store :as st]
|
||||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.shapes.attrs :refer [shape-default-attrs]]
|
||||
[uxbox.main.ui.workspace.sidebar.options.icon-measures :as options-iconm]
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
[cuerdas.core :as str]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.lightbox :as udl]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.main.ui.workspace.base :refer [page-ref]]
|
||||
[uxbox.main.ui.workspace.colorpicker]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.util.data :refer [parse-int]]
|
||||
|
@ -26,7 +26,7 @@
|
|||
(mx/defcs measures-menu
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[own menu]
|
||||
(let [{:keys [id metadata] :as page} (mx/react page-ref)
|
||||
(let [{:keys [id metadata] :as page} (mx/react refs/selected-page)
|
||||
metadata (merge c/page-metadata metadata)]
|
||||
(letfn [(on-size-change [attr]
|
||||
(when-let [value (-> (mx/ref-node own (name attr))
|
||||
|
@ -101,7 +101,7 @@
|
|||
(mx/defcs grid-options-menu
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[own menu]
|
||||
(let [{:keys [id metadata] :as page} (mx/react page-ref)
|
||||
(let [{:keys [id metadata] :as page} (mx/react refs/selected-page)
|
||||
metadata (merge c/page-metadata metadata)]
|
||||
(letfn [(on-x-change []
|
||||
(when-let [value (-> (mx/ref-node own "x-axis")
|
||||
|
|
|
@ -7,17 +7,15 @@
|
|||
|
||||
(ns uxbox.main.ui.workspace.sidebar.options.text
|
||||
(:require [lentes.core :as l]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.main.data.workspace :as udw]
|
||||
[uxbox.main.data.shapes :as uds]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.geom :as geom]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.math :refer (precision-or-0)]
|
||||
[uxbox.util.data :refer (parse-int
|
||||
|
|
|
@ -8,20 +8,20 @@
|
|||
(ns uxbox.main.ui.workspace.sidebar.sitemap
|
||||
(:require [lentes.core :as l]
|
||||
[cuerdas.core :as str]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.data :refer (classnames)]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.store :as st]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.data.projects :as dp]
|
||||
[uxbox.main.data.pages :as udp]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.data.lightbox :as udl]
|
||||
[uxbox.main.ui.workspace.base :as wb]
|
||||
[uxbox.main.ui.workspace.sidebar.sitemap-pageform]
|
||||
[uxbox.main.ui.lightbox :as lbx]
|
||||
[uxbox.main.ui.icons :as i]
|
||||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.main.ui.lightbox :as lbx]
|
||||
[uxbox.util.i18n :refer (tr)]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.data :refer (classnames)]
|
||||
[uxbox.util.dom.dnd :as dnd]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
|
@ -122,9 +122,9 @@
|
|||
(mx/defc sitemap-toolbox
|
||||
{:mixins [mx/static mx/reactive]}
|
||||
[]
|
||||
(let [project (mx/react wb/project-ref)
|
||||
(let [project (mx/react refs/selected-project)
|
||||
pages (mx/react pages-ref)
|
||||
current (mx/react wb/page-ref)
|
||||
current (mx/react refs/selected-page)
|
||||
create #(udl/open! :page-form {:page {:project (:id project)}})
|
||||
close #(st/emit! (dw/toggle-flag :sitemap))]
|
||||
[:div.sitemap.tool-window
|
||||
|
|
43
frontend/src/uxbox/main/workers.cljs
Normal file
43
frontend/src/uxbox/main/workers.cljs
Normal file
|
@ -0,0 +1,43 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; 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-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.workers
|
||||
"A interface to webworkers exposed functionality."
|
||||
(:require [cljs.spec :as s]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.spec :as us]
|
||||
[uxbox.util.workers :as uw]))
|
||||
|
||||
(s/def ::width number?)
|
||||
(s/def ::height number?)
|
||||
(s/def ::x-axis number?)
|
||||
(s/def ::y-axis number?)
|
||||
|
||||
(s/def ::initialize-alignment-params
|
||||
(s/keys :req-un [::width
|
||||
::height
|
||||
::x-axis
|
||||
::y-axis]))
|
||||
|
||||
;; This excludes webworker instantiation on nodejs where
|
||||
;; the tests are run.
|
||||
|
||||
(when (not= *target* "nodejs")
|
||||
(defonce worker (uw/init "/js/worker.js")))
|
||||
|
||||
(defn align-point
|
||||
[point]
|
||||
|
||||
(let [message {:cmd :grid-align :point point}]
|
||||
(->> (uw/ask! worker message)
|
||||
(rx/map :point))))
|
||||
|
||||
(defn initialize-alignment
|
||||
[params]
|
||||
{:pre [(us/valid? ::initialize-alignment-params params)]}
|
||||
(let [message (assoc params :cmd :grid-init)]
|
||||
(uw/send! worker message)))
|
|
@ -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-2017 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.store
|
||||
(:require [beicon.core :as rx]
|
||||
|
@ -16,6 +16,7 @@
|
|||
(defonce state (atom {}))
|
||||
(defonce loader (atom false))
|
||||
(defonce store (ptk/store {:on-error #(*on-error* %)}))
|
||||
(defonce stream (ptk/input-stream store))
|
||||
|
||||
(def auth-ref
|
||||
(-> (l/key :auth)
|
||||
|
|
Loading…
Add table
Reference in a new issue