0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

Minor project structure improvement.

This commit is contained in:
Andrey Antukh 2015-12-17 16:43:58 +02:00
parent a2c313dfc0
commit b317ee4904
17 changed files with 106 additions and 115 deletions

View file

@ -1,19 +1,15 @@
(ns uxbox.core
(:require [uxbox.ui :as ui]
(:require [beicon.core :as rx]
[uxbox.router]
[uxbox.state :as s]
[uxbox.rstore :as rs]
[uxbox.data.projects :as dp]
[uxbox.data.load :as dl]
[goog.dom :as dom]
[beicon.core :as rx]))
[uxbox.ui :as ui]
[uxbox.data.load :as dl]))
(enable-console-print!)
(defonce +setup+
(do
(println "BOOTSTRAP")
(ui/init)
(rs/emit! (dl/load-data))
(rx/on-value s/stream #(dl/persist-state %))

View file

@ -2,7 +2,6 @@
(:require [bidi.router]
[bidi.bidi :as bidi]
[goog.events :as events]
[uxbox.state]
[uxbox.rstore :as rs]))
(enable-console-print!)

View file

@ -1,6 +1,6 @@
(ns uxbox.state
(:require [uxbox.rstore :as rs]
[beicon.core :as rx]))
(:require [beicon.core :as rx]
[uxbox.rstore :as rs]))
(enable-console-print!)

View file

@ -5,13 +5,15 @@
[cats.labs.lens :as l]
[uxbox.state :as s]
[uxbox.rstore :as rs]
[uxbox.util :as util]
[uxbox.data.projects :as dp]
[uxbox.ui.lightbox :as ui.lb]
[uxbox.ui.users :as ui.users]
[uxbox.ui.dashboard.projects :as ui.dashboard.projects]
[uxbox.ui.dashboard.elements :as ui.dashboard.elements]
[uxbox.ui.workspace :as ui.w]))
[uxbox.ui.workspace :as ui.w]
[uxbox.ui.util :as util]
[uxbox.ui.mixins :as mx]))
(def ^:static state
(as-> (l/select-keys [:location :location-params]) $
@ -40,5 +42,5 @@
[]
(let [app-dom (gdom/getElement "app")
lb-dom (gdom/getElement "lightbox")]
(rum/mount (app) app-dom)
(rum/mount (ui.lb/lightbox) lb-dom)))
(util/mount (app) app-dom)
(util/mount (ui.lb/lightbox) lb-dom)))

View file

@ -6,7 +6,8 @@
[uxbox.ui.icons :as i]
[uxbox.ui.lightbox :as lightbox]
[uxbox.ui.dom :as dom]
[uxbox.util :as util]))
[uxbox.ui.mixins :as mx]
[uxbox.ui.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Elements
@ -125,7 +126,7 @@
(util/component
{:render elements-render
:name "elements"
:mixins [rum/static]}))
:mixins [mx/static]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Icons
@ -279,7 +280,7 @@
(util/component
{:render icons-render
:name "icons"
:mixins [rum/static]}))
:mixins [mx/static]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Colors
@ -411,7 +412,7 @@
(util/component
{:render colors-render
:name "colors"
:mixins [rum/static]}))
:mixins [mx/static]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lightbox

View file

@ -2,20 +2,19 @@
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[cats.labs.lens :as l]
[uxbox.util :as util]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as s]
[uxbox.data.projects :as dp]
[uxbox.ui.navigation :as nav]
[uxbox.ui.icons :as i]
[uxbox.ui.users :as ui.u]))
[uxbox.ui.users :as ui.u]
[uxbox.ui.util :as util]))
(def ^:static header-state
(as-> (l/in [:dashboard]) $
(l/focus-atom $ s/state)))
(defn- header-link
[section content]
(let [link (r/route-for section)

View file

@ -3,17 +3,17 @@
[rum.core :as rum]
[cats.labs.lens :as l]
[cuerdas.core :as str]
[uxbox.util :as util]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as s]
[uxbox.time :as time]
[uxbox.data.projects :as dp]
[uxbox.ui.icons.dashboard :as icons]
[uxbox.ui.icons :as i]
[uxbox.ui.dom :as dom]
[uxbox.ui.dashboard.header :as dsh.header]
[uxbox.ui.lightbox :as lightbox]
[uxbox.time :refer [ago]]))
[uxbox.ui.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers & Constants
@ -195,7 +195,7 @@
:key (:id project)}
[:h3 (:name project)]
[:span.project-th-update
(str "Updated " (ago (:last-update project)))]
(str "Updated " (time/ago (:last-update project)))]
[:div.project-th-actions
[:div.project-th-icon.pages
icons/page

View file

@ -1,7 +1,8 @@
(ns uxbox.ui.library-bar
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[uxbox.util :as util]
[uxbox.ui.util :as ui]
[uxbox.ui.mixins :as mx]
[uxbox.ui.icons :as i]))
(defn library-bar-render
@ -78,7 +79,7 @@
]))
(def ^:static library-bar
(util/component
(ui/component
{:render library-bar-render
:name "library-bar"
:mixins [rum/static]}))
:mixins [mx/static]}))

View file

@ -1,7 +1,7 @@
(ns uxbox.ui.lightbox
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[uxbox.util :as util]
[uxbox.ui.util :as util]
[uxbox.ui.keyboard :as k]
[goog.events :as events])
(:import goog.events.EventType))

View file

@ -1,38 +1,9 @@
(ns uxbox.util
(ns uxbox.ui.mixins
(:refer-clojure :exclude [derive])
(:require [rum.core :as rum]
[cats.labs.lens :as l]
[goog.dom.forms :as gforms]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sugar for define rum components
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn component
[spec]
(let [name (or (:name spec)
(str (gensym "rum-")))
mixins (or (:mixins spec)
[])
spec (merge (dissoc spec :name :mixins)
(when-let [rfn (:render spec)]
{:render (fn [state]
[(apply rfn state (:rum/props state)) state])}))
cls (rum/build-class (conj mixins spec) name)
ctr (fn self
([] (self {}))
([& props]
(let [state {:rum/props props}]
(rum/element cls state nil))))]
(with-meta ctr {:rum/class cls})))
(defn ref-value
[own ref]
(let [component (-> own :rum/react-component)
ref-node (aget (.-refs component) ref)
dom-node (.findDOMNode js/ReactDOM ref-node)]
(.-value dom-node)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Cursored & Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -116,44 +87,3 @@
{:should-update
(fn [old-state new-state]
(not= (:rum/props old-state) (:rum/props new-state)))})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lenses & Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn dep-in
[where link]
{:pre [(vector? where) (vector? link)]}
(l/lens
(fn [s]
(let [value (get-in s link)
path (conj where value)]
(get-in s path)))
(fn [s f]
(throw (ex-info "Not implemented" {})))))
(defn getter
[f]
(l/lens f #(throw (ex-info "Not implemented" {}))))
(defn derive
[a path]
(l/focus-atom (l/in path) a))
(defn focus
([state]
(l/focus-atom l/id state))
([lens state]
(l/focus-atom lens state)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dom Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn prevent-default
[e]
(.preventDefault e))
(defn get-value
[el]
(gforms/getValue el))

View file

@ -4,9 +4,9 @@
[rum.core :as rum]
[uxbox.router :as r]
[uxbox.state :as s]
[uxbox.util :as util]
[uxbox.ui.icons :as icons]
[uxbox.ui.navigation :as nav]))
[uxbox.ui.navigation :as nav]
[uxbox.ui.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Menu

View file

@ -0,0 +1,33 @@
(ns uxbox.ui.util
"A collection of sugar syntax for define react
components using rum libary."
(:refer-clojure :exclude [derive])
(:require [rum.core :as rum]))
(defn component
[spec]
(let [name (or (:name spec)
(str (gensym "rum-")))
mixins (or (:mixins spec)
[])
spec (merge (dissoc spec :name :mixins)
(when-let [rfn (:render spec)]
{:render (fn [state]
[(apply rfn state (:rum/props state)) state])}))
cls (rum/build-class (conj mixins spec) name)
ctr (fn self
([] (self {}))
([& props]
(let [state {:rum/props props}]
(rum/element cls state nil))))]
(with-meta ctr {:rum/class cls})))
(defn ref-value
[own ref]
(let [component (-> own :rum/react-component)
ref-node (aget (.-refs component) ref)
dom-node (.findDOMNode js/ReactDOM ref-node)]
(.-value dom-node)))
(def mount rum/mount)

View file

@ -1,11 +1,11 @@
(ns uxbox.ui.workspace
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[uxbox.util :as util]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as s]
[uxbox.data.projects :as dp]
[uxbox.ui.util :as util]
[uxbox.ui.workspace.base :as wb]
[uxbox.ui.workspace.rules :as wr]
[uxbox.ui.workspace.workarea :as wa]))

View file

@ -4,34 +4,35 @@
[beicon.core :as rx]
[cats.labs.lens :as l]
[cuerdas.core :as str]
[uxbox.util :as util]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as s]
[uxbox.data.projects :as dp]
[uxbox.data.workspace :as dw]
[uxbox.util.lens :as ul]
[uxbox.ui.icons.dashboard :as icons]
[uxbox.ui.icons :as i]
[uxbox.ui.lightbox :as lightbox]
[uxbox.ui.keyboard :as k]
[uxbox.ui.users :as ui.u]
[uxbox.ui.navigation :as nav]
[uxbox.ui.dom :as dom]))
[uxbox.ui.dom :as dom]
[uxbox.ui.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static project-state
(as-> (util/dep-in [:projects-by-id] [:workspace :project]) $
(as-> (ul/dep-in [:projects-by-id] [:workspace :project]) $
(l/focus-atom $ s/state)))
(def ^:static page-state
(as-> (util/dep-in [:pages-by-id] [:workspace :page]) $
(as-> (ul/dep-in [:pages-by-id] [:workspace :page]) $
(l/focus-atom $ s/state)))
(def ^:static pages-state
(as-> (util/getter #(let [pid (get-in % [:workspace :project])]
(as-> (ul/getter #(let [pid (get-in % [:workspace :project])]
(dp/project-pages % pid))) $
(l/focus-atom $ s/state)))

View file

@ -3,10 +3,11 @@
[rum.core :as rum]
[cuerdas.core :as str]
[beicon.core :as rx]
[uxbox.util :as util]
[uxbox.state :as s]
[uxbox.ui.dom :as dom]
[uxbox.ui.workspace.base :as wd]))
[uxbox.ui.workspace.base :as wd]
[uxbox.ui.util :as util]))
(def viewport-height 3000)
(def viewport-width 3000)

View file

@ -1,14 +1,14 @@
(ns uxbox.ui.workspace.workarea
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[uxbox.util :as util]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as s]
[uxbox.data.projects :as dp]
[uxbox.ui.workspace.base :as wb]
[uxbox.ui.workspace.rules :as wr]))
[uxbox.ui.workspace.rules :as wr]
[uxbox.ui.mixins :as mx]
[uxbox.ui.util :as util]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Coordinates Debug
@ -47,7 +47,7 @@
(util/component
{:render background-render
:name "background"
:mixins [util/static]}))
:mixins [mx/static]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -123,7 +123,7 @@
(util/component
{:render grid-render
:name "grid"
:mixins [util/static]}))
:mixins [mx/static]}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Canvas

View file

@ -0,0 +1,28 @@
(ns uxbox.util.lens
(:refer-clojure :exclude [derive])
(:require [cats.labs.lens :as l]))
(defn dep-in
[where link]
{:pre [(vector? where) (vector? link)]}
(l/lens
(fn [s]
(let [value (get-in s link)
path (conj where value)]
(get-in s path)))
(fn [s f]
(throw (ex-info "Not implemented" {})))))
(defn getter
[f]
(l/lens f #(throw (ex-info "Not implemented" {}))))
(defn derive
[a path]
(l/focus-atom (l/in path) a))
(defn focus
([state]
(l/focus-atom l/id state))
([lens state]
(l/focus-atom lens state)))