mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
Move shapes rendering implementation under uxbox.ui namespace.
This commit is contained in:
parent
d833543368
commit
b937408bab
3 changed files with 47 additions and 37 deletions
|
@ -1,6 +1,4 @@
|
||||||
(ns uxbox.shapes
|
(ns uxbox.shapes)
|
||||||
(:require [sablono.core :refer-macros [html]]
|
|
||||||
[uxbox.util.data :refer (remove-nil-vals)]))
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Types
|
;; Types
|
||||||
|
@ -28,11 +26,11 @@
|
||||||
([shape attrs] (-render shape attrs)))
|
([shape attrs] (-render shape attrs)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Implementation
|
;; Implementation Api
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn- dispatch-by-type
|
(defn- dispatch-by-type
|
||||||
[shape props]
|
[shape & params]
|
||||||
(:type shape))
|
(:type shape))
|
||||||
|
|
||||||
(defmulti -render
|
(defmulti -render
|
||||||
|
@ -43,37 +41,9 @@
|
||||||
dispatch-by-type
|
dispatch-by-type
|
||||||
:hierarchy #'+hierarchy+)
|
:hierarchy #'+hierarchy+)
|
||||||
|
|
||||||
(defn transform-attrs
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
[{:keys [view-box] :as data}]
|
;; Implementation
|
||||||
(if view-box
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(assoc data :view-box (apply str (interpose " " view-box)))
|
|
||||||
data))
|
|
||||||
|
|
||||||
(defn extract-attrs
|
|
||||||
"Extract predefinet attrs from shapes."
|
|
||||||
[shape]
|
|
||||||
(select-keys shape [:width :height :view-box :x :y :cx :cy]))
|
|
||||||
|
|
||||||
(defmethod -render :builtin/icon
|
|
||||||
[{:keys [data id] :as shape} attrs]
|
|
||||||
(let [attrs (as-> shape $
|
|
||||||
(extract-attrs $)
|
|
||||||
(remove-nil-vals $)
|
|
||||||
(merge $ attrs)
|
|
||||||
(transform-attrs $))]
|
|
||||||
(html
|
|
||||||
[:svg (merge attrs {:key (str id)}) data])))
|
|
||||||
|
|
||||||
(defmethod -render :builtin/icon-svg
|
|
||||||
[{:keys [image id] :as shape} attrs]
|
|
||||||
(let [attrs (as-> shape $
|
|
||||||
(extract-attrs $)
|
|
||||||
(remove-nil-vals $)
|
|
||||||
(merge $ attrs)
|
|
||||||
(transform-attrs $))]
|
|
||||||
(html
|
|
||||||
[:svg (merge attrs {:key (str id)})
|
|
||||||
[:image image]])))
|
|
||||||
|
|
||||||
(defmethod -move ::shape
|
(defmethod -move ::shape
|
||||||
[shape {:keys [dx dy] :as opts}]
|
[shape {:keys [dx dy] :as opts}]
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
[uxbox.ui.dashboard :as dashboard]
|
[uxbox.ui.dashboard :as dashboard]
|
||||||
[uxbox.ui.workspace :refer (workspace)]
|
[uxbox.ui.workspace :refer (workspace)]
|
||||||
[uxbox.ui.util :as util]
|
[uxbox.ui.util :as util]
|
||||||
[uxbox.ui.mixins :as mx]))
|
[uxbox.ui.mixins :as mx]
|
||||||
|
[uxbox.ui.shapes]))
|
||||||
|
|
||||||
(def ^:static state
|
(def ^:static state
|
||||||
(as-> (l/select-keys [:location :location-params]) $
|
(as-> (l/select-keys [:location :location-params]) $
|
||||||
|
|
39
frontend/uxbox/ui/shapes.cljs
Normal file
39
frontend/uxbox/ui/shapes.cljs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
(ns uxbox.ui.shapes
|
||||||
|
"A ui related implementation for uxbox.shapes ns."
|
||||||
|
(:require [sablono.core :refer-macros [html]]
|
||||||
|
[uxbox.shapes :as shapes]
|
||||||
|
[uxbox.util.data :refer (remove-nil-vals)]))
|
||||||
|
|
||||||
|
(defn- transform-attrs
|
||||||
|
[{:keys [view-box] :as data}]
|
||||||
|
(if view-box
|
||||||
|
(assoc data :view-box (apply str (interpose " " view-box)))
|
||||||
|
data))
|
||||||
|
|
||||||
|
(defn- extract-attrs
|
||||||
|
"Extract predefinet attrs from shapes."
|
||||||
|
[shape]
|
||||||
|
(select-keys shape [:width :height :view-box :x :y :cx :cy]))
|
||||||
|
|
||||||
|
(defmethod shapes/-render :builtin/icon
|
||||||
|
[{:keys [data id] :as shape} attrs]
|
||||||
|
(let [attrs (as-> shape $
|
||||||
|
(extract-attrs $)
|
||||||
|
(remove-nil-vals $)
|
||||||
|
(merge $ attrs)
|
||||||
|
(transform-attrs $))]
|
||||||
|
(html
|
||||||
|
[:svg (merge attrs {:key (str id)}) data])))
|
||||||
|
|
||||||
|
(defmethod shapes/-render :builtin/icon-svg
|
||||||
|
[{:keys [image id] :as shape} attrs]
|
||||||
|
(let [attrs (as-> shape $
|
||||||
|
(extract-attrs $)
|
||||||
|
(remove-nil-vals $)
|
||||||
|
(merge $ attrs)
|
||||||
|
(transform-attrs $))]
|
||||||
|
(html
|
||||||
|
[:svg (merge attrs {:key (str id)})
|
||||||
|
[:image image]])))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue