0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 01:01:30 -05:00

Fix linter issues on frontend (part 4).

This commit is contained in:
Andrey Antukh 2021-06-17 16:29:52 +02:00 committed by Andrés Moya
parent 30e77556db
commit e0846ce00e
26 changed files with 130 additions and 195 deletions

View file

@ -6,13 +6,12 @@
(ns app.main.ui.handoff.attributes.layout (ns app.main.ui.handoff.attributes.layout
(:require (:require
[rumext.alpha :as mf]
[cuerdas.core :as str]
[app.util.i18n :refer [t]]
[app.common.math :as mth] [app.common.math :as mth]
[app.main.ui.icons :as i] [app.main.ui.components.copy-button :refer [copy-button]]
[app.util.code-gen :as cg] [app.util.code-gen :as cg]
[app.main.ui.components.copy-button :refer [copy-button]])) [app.util.i18n :refer [t]]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(def properties [:width :height :x :y :radius :rx :r1]) (def properties [:width :height :x :y :radius :rx :r1])

View file

@ -6,15 +6,13 @@
(ns app.main.ui.handoff.attributes.shadow (ns app.main.ui.handoff.attributes.shadow
(:require (:require
[rumext.alpha :as mf]
[cuerdas.core :as str]
[app.common.data :as d] [app.common.data :as d]
[app.util.i18n :refer [t]]
[app.util.code-gen :as cg]
[app.main.ui.icons :as i]
[app.util.code-gen :as cg]
[app.main.ui.components.copy-button :refer [copy-button]] [app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.handoff.attributes.common :refer [color-row]])) [app.main.ui.handoff.attributes.common :refer [color-row]]
[app.util.code-gen :as cg]
[app.util.i18n :refer [tr]]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(defn has-shadow? [shape] (defn has-shadow? [shape]
(:shadow shape)) (:shadow shape))
@ -33,26 +31,25 @@
{:to-prop "box-shadow" {:to-prop "box-shadow"
:format #(cg/shadow->css shadow)})) :format #(cg/shadow->css shadow)}))
(mf/defc shadow-block [{:keys [shape locale shadow]}] (mf/defc shadow-block [{:keys [shadow]}]
(let [color-format (mf/use-state :hex) (let [color-format (mf/use-state :hex)]
copy-data (shadow-copy-data shadow)]
[:div.attributes-shadow-block [:div.attributes-shadow-block
[:div.attributes-shadow-row [:div.attributes-shadow-row
[:div.attributes-label (->> shadow :style d/name (str "handoff.attributes.shadow.style.") (t locale))] [:div.attributes-label (->> shadow :style d/name (str "handoff.attributes.shadow.style.") (tr))]
[:div.attributes-shadow [:div.attributes-shadow
[:div.attributes-label (t locale "handoff.attributes.shadow.shorthand.offset-x")] [:div.attributes-label (tr "handoff.attributes.shadow.shorthand.offset-x")]
[:div.attributes-value (str (:offset-x shadow))]] [:div.attributes-value (str (:offset-x shadow))]]
[:div.attributes-shadow [:div.attributes-shadow
[:div.attributes-label (t locale "handoff.attributes.shadow.shorthand.offset-y")] [:div.attributes-label (tr "handoff.attributes.shadow.shorthand.offset-y")]
[:div.attributes-value (str (:offset-y shadow))]] [:div.attributes-value (str (:offset-y shadow))]]
[:div.attributes-shadow [:div.attributes-shadow
[:div.attributes-label (t locale "handoff.attributes.shadow.shorthand.blur")] [:div.attributes-label (tr "handoff.attributes.shadow.shorthand.blur")]
[:div.attributes-value (str (:blur shadow))]] [:div.attributes-value (str (:blur shadow))]]
[:div.attributes-shadow [:div.attributes-shadow
[:div.attributes-label (t locale "handoff.attributes.shadow.shorthand.spread")] [:div.attributes-label (tr "handoff.attributes.shadow.shorthand.spread")]
[:div.attributes-value (str (:spread shadow))]] [:div.attributes-value (str (:spread shadow))]]
[:& copy-button {:data (shadow-copy-data shadow)}]] [:& copy-button {:data (shadow-copy-data shadow)}]]
@ -61,12 +58,12 @@
:format @color-format :format @color-format
:on-change-format #(reset! color-format %)}]])) :on-change-format #(reset! color-format %)}]]))
(mf/defc shadow-panel [{:keys [shapes locale]}] (mf/defc shadow-panel [{:keys [shapes]}]
(let [shapes (->> shapes (filter has-shadow?))] (let [shapes (->> shapes (filter has-shadow?))]
(when (seq shapes) (when (seq shapes)
[:div.attributes-block [:div.attributes-block
[:div.attributes-block-title [:div.attributes-block-title
[:div.attributes-block-title-text (t locale "handoff.attributes.shadow")] [:div.attributes-block-title-text (tr "handoff.attributes.shadow")]
(when (= (count shapes) 1) (when (= (count shapes) 1)
[:& copy-button {:data (shape-copy-data (first shapes))}])] [:& copy-button {:data (shape-copy-data (first shapes))}])]
@ -74,5 +71,4 @@
(for [shape shapes] (for [shape shapes]
(for [shadow (:shadow shape)] (for [shadow (:shadow shape)]
[:& shadow-block {:shape shape [:& shadow-block {:shape shape
:locale locale
:shadow shadow}]))]]))) :shadow shadow}]))]])))

View file

@ -6,16 +6,15 @@
(ns app.main.ui.handoff.attributes.stroke (ns app.main.ui.handoff.attributes.stroke
(:require (:require
[rumext.alpha :as mf]
[cuerdas.core :as str]
[app.common.data :as d] [app.common.data :as d]
[app.common.math :as mth] [app.common.math :as mth]
[app.util.i18n :refer [t]]
[app.util.color :as uc]
[app.main.ui.icons :as i]
[app.util.code-gen :as cg]
[app.main.ui.components.copy-button :refer [copy-button]] [app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.handoff.attributes.common :refer [color-row]])) [app.main.ui.handoff.attributes.common :refer [color-row]]
[app.util.code-gen :as cg]
[app.util.color :as uc]
[app.util.i18n :refer [t]]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(defn shape->color [shape] (defn shape->color [shape]
{:color (:stroke-color shape) {:color (:stroke-color shape)

View file

@ -6,14 +6,14 @@
(ns app.main.ui.handoff.attributes.svg (ns app.main.ui.handoff.attributes.svg
(:require (:require
[rumext.alpha :as mf]
[app.common.data :as d]
[cuerdas.core :as str]
[app.util.i18n :refer [tr]]
#_[app.common.math :as mth] #_[app.common.math :as mth]
#_[app.main.ui.icons :as i] #_[app.main.ui.icons :as i]
#_[app.util.code-gen :as cg] #_[app.util.code-gen :as cg]
[app.main.ui.components.copy-button :refer [copy-button]])) [app.common.data :as d]
[app.main.ui.components.copy-button :refer [copy-button]]
[app.util.i18n :refer [tr]]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(defn map->css [attr] (defn map->css [attr]
@ -47,7 +47,7 @@
[{:keys [shapes]}] [{:keys [shapes]}]
(let [shape (first shapes)] (let [shape (first shapes)]
(when (and (:svg-attrs shape) (not (empty? (:svg-attrs shape)))) (when (seq (:svg-attrs shape))
[:div.attributes-block [:div.attributes-block
[:div.attributes-block-title [:div.attributes-block-title
[:div.attributes-block-title-text (tr "workspace.sidebar.options.svg-attrs.title")]] [:div.attributes-block-title-text (tr "workspace.sidebar.options.svg-attrs.title")]]

View file

@ -11,11 +11,9 @@
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.copy-button :refer [copy-button]] [app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.handoff.attributes.common :refer [color-row]] [app.main.ui.handoff.attributes.common :refer [color-row]]
[app.main.ui.icons :as i]
[app.util.i18n :refer [tr]]
[app.util.code-gen :as cg] [app.util.code-gen :as cg]
[app.util.color :as uc] [app.util.color :as uc]
[app.util.webapi :as wapi] [app.util.i18n :refer [tr]]
[cuerdas.core :as str] [cuerdas.core :as str]
[okulary.core :as l] [okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
@ -68,7 +66,7 @@
([style & properties] ([style & properties]
(cg/generate-css-props style properties params))) (cg/generate-css-props style properties params)))
(mf/defc typography-block [{:keys [shape text style full-style]}] (mf/defc typography-block [{:keys [text style full-style]}]
(let [typography-library-ref (mf/use-memo (let [typography-library-ref (mf/use-memo
(mf/deps (:typography-ref-file style)) (mf/deps (:typography-ref-file style))
(make-typographies-library-ref (:typography-ref-file style))) (make-typographies-library-ref (:typography-ref-file style)))
@ -77,7 +75,6 @@
file-typographies (mf/deref file-typographies-ref) file-typographies (mf/deref file-typographies-ref)
color-format (mf/use-state :hex) color-format (mf/use-state :hex)
color (shape->color style)
typography (get (or typography-library file-typographies) (:typography-ref-id style))] typography (get (or typography-library file-typographies) (:typography-ref-id style))]
@ -163,14 +160,11 @@
m1)) m1))
(mf/defc text-block [{:keys [shape]}] (mf/defc text-block [{:keys [shape]}]
(let [font (cg/search-text-attrs (:content shape) (let [style-text-blocks (->> (keys txt/default-text-attrs)
(keys txt/default-text-attrs))
style-text-blocks (->> (keys txt/default-text-attrs)
(cg/parse-style-text-blocks (:content shape)) (cg/parse-style-text-blocks (:content shape))
(remove (fn [[style text]] (str/empty? (str/trim text)))) (remove (fn [[_ text]] (str/empty? (str/trim text))))
(mapv (fn [[style text]] (vector (merge txt/default-text-attrs style) text)))) (mapv (fn [[style text]] (vector (merge txt/default-text-attrs style) text))))]
font (merge txt/default-text-attrs font)]
(for [[idx [full-style text]] (map-indexed vector style-text-blocks)] (for [[idx [full-style text]] (map-indexed vector style-text-blocks)]
(let [previus-style (first (nth style-text-blocks (dec idx) nil)) (let [previus-style (first (nth style-text-blocks (dec idx) nil))
style (remove-equal-values full-style previus-style) style (remove-equal-values full-style previus-style)

View file

@ -7,17 +7,16 @@
(ns app.main.ui.handoff.code (ns app.main.ui.handoff.code
(:require (:require
["js-beautify" :as beautify] ["js-beautify" :as beautify]
[cuerdas.core :as str]
[rumext.alpha :as mf]
[app.util.i18n :as i18n]
[app.util.dom :as dom]
[app.util.code-gen :as cg]
[app.main.ui.icons :as i]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.main.ui.components.code-block :refer [code-block]]
[app.main.ui.components.copy-button :refer [copy-button]] [app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.components.code-block :refer [code-block]])) [app.main.ui.icons :as i]
[app.util.code-gen :as cg]
[app.util.dom :as dom]
[cuerdas.core :as str]
[rumext.alpha :as mf]))
(defn generate-markup-code [type shapes] (defn generate-markup-code [_type shapes]
(let [frame (dom/query js/document "#svg-frame") (let [frame (dom/query js/document "#svg-frame")
markup-shape markup-shape
(fn [shape] (fn [shape]
@ -42,8 +41,6 @@
[{:keys [shapes frame on-expand]}] [{:keys [shapes frame on-expand]}]
(let [style-type (mf/use-state "css") (let [style-type (mf/use-state "css")
markup-type (mf/use-state "svg") markup-type (mf/use-state "svg")
locale (mf/deref i18n/locale)
shapes (->> shapes shapes (->> shapes
(map #(gsh/translate-to-frame % frame))) (map #(gsh/translate-to-frame % frame)))

View file

@ -6,21 +6,19 @@
(ns app.main.ui.handoff.exports (ns app.main.ui.handoff.exports
(:require (:require
[rumext.alpha :as mf]
[beicon.core :as rx]
[app.util.i18n :refer [t] :as i18n]
[app.common.geom.shapes :as gsh]
[app.main.ui.icons :as i]
[app.common.data :as d] [app.common.data :as d]
[app.util.dom :as dom]
[app.main.store :as st]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.ui.workspace.sidebar.options.menus.exports :as we])) [app.main.store :as st]
[app.main.ui.icons :as i]
[app.main.ui.workspace.sidebar.options.menus.exports :as we]
[app.util.dom :as dom]
[app.util.i18n :refer [tr]]
[beicon.core :as rx]
[rumext.alpha :as mf]))
(mf/defc exports (mf/defc exports
[{:keys [shape page-id file-id] :as props}] [{:keys [shape page-id file-id] :as props}]
(let [locale (mf/deref i18n/locale) (let [exports (mf/use-state (:exports shape []))
exports (mf/use-state (:exports shape []))
loading? (mf/use-state false) loading? (mf/use-state false)
on-download on-download
@ -35,7 +33,7 @@
(js/console.log status body) (js/console.log status body)
(if (= status 200) (if (= status 200)
(dom/trigger-download (:name shape) body) (dom/trigger-download (:name shape) body)
(st/emit! (dm/error (t locale "errors.unexpected-error"))))) (st/emit! (dm/error (tr "errors.unexpected-error")))))
(constantly nil) (constantly nil)
(fn [] (fn []
(swap! loading? not)))))) (swap! loading? not))))))
@ -90,7 +88,7 @@
[:div.element-set.exports-options [:div.element-set.exports-options
[:div.element-set-title [:div.element-set-title
[:span (t locale "workspace.options.export")] [:span (tr "workspace.options.export")]
[:div.add-page {:on-click add-export} i/close]] [:div.add-page {:on-click add-export} i/close]]
(when (seq @exports) (when (seq @exports)
@ -124,6 +122,6 @@
:class (dom/classnames :btn-disabled @loading?) :class (dom/classnames :btn-disabled @loading?)
:disabled @loading?} :disabled @loading?}
(if @loading? (if @loading?
(t locale "workspace.options.exporting-object") (tr "workspace.options.exporting-object")
(t locale "workspace.options.export-object"))]])])) (tr "workspace.options.export-object"))]])]))

View file

@ -7,11 +7,10 @@
(ns app.main.ui.handoff.left-sidebar (ns app.main.ui.handoff.left-sidebar
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.uuid :as uuid]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.workspace.sidebar.layers :refer [element-icon layer-name frame-wrapper]] [app.main.ui.workspace.sidebar.layers :refer [element-icon layer-name]]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.keyboard :as kbd] [app.util.keyboard :as kbd]
[okulary.core :as l] [okulary.core :as l]
@ -29,7 +28,7 @@
(l/derived st/state))) (l/derived st/state)))
(mf/defc layer-item (mf/defc layer-item
[{:keys [index item selected objects disable-collapse?] :as props}] [{:keys [item selected objects disable-collapse?] :as props}]
(let [id (:id item) (let [id (:id item)
selected? (contains? selected id) selected? (contains? selected id)
item-ref (mf/use-ref nil) item-ref (mf/use-ref nil)

View file

@ -7,50 +7,46 @@
(ns app.main.ui.handoff.render (ns app.main.ui.handoff.render
"The main container for a frame in handoff mode" "The main container for a frame in handoff mode"
(:require (:require
[rumext.alpha :as mf]
[app.util.object :as obj]
[app.util.dom :as dom]
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.main.refs :as refs] [app.common.pages :as cp]
[app.main.store :as st]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
[app.main.ui.shapes.filters :as filters] [app.main.store :as st]
[app.main.ui.handoff.selection-feedback :refer [selection-feedback]]
[app.main.ui.shapes.circle :as circle] [app.main.ui.shapes.circle :as circle]
[app.main.ui.shapes.frame :as frame] [app.main.ui.shapes.frame :as frame]
[app.main.ui.shapes.group :as group] [app.main.ui.shapes.group :as group]
[app.main.ui.shapes.svg-raw :as svg-raw]
[app.main.ui.shapes.image :as image] [app.main.ui.shapes.image :as image]
[app.main.ui.shapes.path :as path] [app.main.ui.shapes.path :as path]
[app.main.ui.shapes.rect :as rect] [app.main.ui.shapes.rect :as rect]
[app.main.ui.shapes.shape :refer [shape-container]]
[app.main.ui.shapes.svg-raw :as svg-raw]
[app.main.ui.shapes.text :as text] [app.main.ui.shapes.text :as text]
[app.main.ui.handoff.selection-feedback :refer [selection-feedback]] [app.util.dom :as dom]
[app.main.ui.shapes.shape :refer [shape-container]])) [app.util.object :as obj]
[rumext.alpha :as mf]))
(declare shape-container-factory) (declare shape-container-factory)
(defn handle-hover-shape [{:keys [type id]} hover?] (defn handle-hover-shape [{:keys [type id]} hover?]
#(when-not (#{:group :frame} type) #(when-not (#{:group :frame} type)
(do (dom/prevent-default %)
(dom/prevent-default %) (dom/stop-propagation %)
(dom/stop-propagation %) (st/emit! (dv/hover-shape id hover?))))
(st/emit! (dv/hover-shape id hover?)))))
(defn select-shape [{:keys [type id]}] (defn select-shape [{:keys [type id]}]
(fn [event] (fn [event]
(when-not (#{:group :frame} type) (when-not (#{:group :frame} type)
(do (dom/stop-propagation event)
(dom/stop-propagation event) (dom/prevent-default event)
(dom/prevent-default event) (cond
(cond (.-shiftKey event)
(.-shiftKey event) (st/emit! (dv/toggle-selection id))
(st/emit! (dv/toggle-selection id))
:else :else
(st/emit! (dv/select-shape id))))))) (st/emit! (dv/select-shape id))))))
(defn shape-wrapper-factory (defn shape-wrapper-factory
[component] [component]
@ -114,8 +110,8 @@
(defn svg-raw-container-factory (defn svg-raw-container-factory
[objects] [objects]
(let [shape-container (shape-container-factory objects) (let [shape-container (shape-container-factory objects)
svg-raw-shape (svg-raw/svg-raw-shape shape-container) svg-raw-shape (svg-raw/svg-raw-shape shape-container)
svg-raw-wrapper (shape-wrapper-factory svg-raw-shape)] svg-raw-wrapper (shape-wrapper-factory svg-raw-shape)]
(mf/fnc group-container (mf/fnc group-container
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
@ -127,7 +123,7 @@
[:> svg-raw-wrapper props])))) [:> svg-raw-wrapper props]))))
(defn shape-container-factory (defn shape-container-factory
[objects show-interactions?] [objects]
(let [path-wrapper (shape-wrapper-factory path/path-shape) (let [path-wrapper (shape-wrapper-factory path/path-shape)
text-wrapper (shape-wrapper-factory text/text-shape) text-wrapper (shape-wrapper-factory text/text-shape)
rect-wrapper (shape-wrapper-factory rect/rect-shape) rect-wrapper (shape-wrapper-factory rect/rect-shape)

View file

@ -6,16 +6,16 @@
(ns app.main.ui.handoff.right-sidebar (ns app.main.ui.handoff.right-sidebar
(:require (:require
[rumext.alpha :as mf]
[okulary.core :as l]
[app.util.i18n :refer [t] :as i18n]
[app.common.data :as d] [app.common.data :as d]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.icons :as i]
[app.main.ui.components.tab-container :refer [tab-container tab-element]] [app.main.ui.components.tab-container :refer [tab-container tab-element]]
[app.main.ui.workspace.sidebar.layers :refer [element-icon]]
[app.main.ui.handoff.attributes :refer [attributes]] [app.main.ui.handoff.attributes :refer [attributes]]
[app.main.ui.handoff.code :refer [code]])) [app.main.ui.handoff.code :refer [code]]
[app.main.ui.icons :as i]
[app.main.ui.workspace.sidebar.layers :refer [element-icon]]
[app.util.i18n :refer [t] :as i18n]
[okulary.core :as l]
[rumext.alpha :as mf]))
(defn make-selected-shapes-iref (defn make-selected-shapes-iref
[] []

View file

@ -6,15 +6,11 @@
(ns app.main.ui.handoff.selection-feedback (ns app.main.ui.handoff.selection-feedback
(:require (:require
[rumext.alpha :as mf]
[cuerdas.core :as str]
[okulary.core :as l]
[app.common.data :as d]
[app.common.math :as mth]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.point :as gpt]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.measurements :refer [selection-guides size-display measurement]])) [app.main.ui.measurements :refer [selection-guides size-display measurement]]
[okulary.core :as l]
[rumext.alpha :as mf]))
;; ------------------------------------------------ ;; ------------------------------------------------
;; CONSTANTS ;; CONSTANTS
@ -67,7 +63,7 @@
;; COMPONENTS ;; COMPONENTS
;; ------------------------------------------------ ;; ------------------------------------------------
(mf/defc selection-rect [{:keys [frame selrect zoom]}] (mf/defc selection-rect [{:keys [selrect zoom]}]
(let [{:keys [x y width height]} selrect (let [{:keys [x y width height]} selrect
selection-rect-width (/ selection-rect-width zoom)] selection-rect-width (/ selection-rect-width zoom)]
[:g.selection-rect [:g.selection-rect

View file

@ -7,20 +7,14 @@
(ns app.main.ui.hooks (ns app.main.ui.hooks
"A collection of general purpose react hooks." "A collection of general purpose react hooks."
(:require (:require
[app.common.spec :as us]
[app.main.data.shortcuts :as dsc] [app.main.data.shortcuts :as dsc]
[app.main.store :as st] [app.main.store :as st]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.dom.dnd :as dnd] [app.util.dom.dnd :as dnd]
[app.util.logging :as log] [app.util.logging :as log]
[app.util.object :as obj]
[app.util.timers :as ts] [app.util.timers :as ts]
[app.util.webapi :as wapi]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [rumext.alpha :as mf]))
[goog.events :as events]
[rumext.alpha :as mf])
(:import goog.events.EventType))
(log/set-level! :warn) (log/set-level! :warn)
@ -98,10 +92,7 @@
cleanup cleanup
(fn [] (fn []
;; (js/console.log "cleanup" (:name data)) (some-> (:subscr @state) rx/unsub!)
(when-let [subscr (:subscr @state)]
;; (js/console.log "unsubscribing" (:name data))
(rx/unsub! (:subscr @state)))
(swap! state (fn [state] (swap! state (fn [state]
(-> state (-> state
(cancel-timer) (cancel-timer)
@ -118,9 +109,8 @@
(fn [event] (fn [event]
(if disabled (if disabled
(dom/prevent-default event) (dom/prevent-default event)
(let [target (dom/get-target event)] (do
(dom/stop-propagation event) (dom/stop-propagation event)
;; (dnd/trace event data "drag-start")
(dnd/set-data! event data-type data) (dnd/set-data! event data-type data)
(dnd/set-drag-image! event (invisible-image)) (dnd/set-drag-image! event (invisible-image))
(dnd/set-allowed-effect! event "move") (dnd/set-allowed-effect! event "move")
@ -237,7 +227,7 @@
[] []
(try (try
(not js/window) (not js/window)
(catch :default e (catch :default _e
;; When exception accessing window we're in ssr ;; When exception accessing window we're in ssr
true))) true)))

View file

@ -5,7 +5,7 @@
;; Copyright (c) UXBOX Labs SL ;; Copyright (c) UXBOX Labs SL
(ns app.main.ui.icons (ns app.main.ui.icons
(:refer-clojure :exclude [import]) (:refer-clojure :exclude [import mask])
(:require-macros [app.main.ui.icons :refer [icon-xref]]) (:require-macros [app.main.ui.icons :refer [icon-xref]])
(:require [rumext.alpha :as mf])) (:require [rumext.alpha :as mf]))
@ -163,7 +163,7 @@
(mf/defc debug-icons-preview (mf/defc debug-icons-preview
{::mf/wrap-props false} {::mf/wrap-props false}
[props] []
[:section.debug-icons-preview [:section.debug-icons-preview
(for [[key val] (sort-by first (ns-publics 'app.main.ui.icons))] (for [[key val] (sort-by first (ns-publics 'app.main.ui.icons))]
(when (not= key 'debug-icons-preview) (when (not= key 'debug-icons-preview)

View file

@ -6,9 +6,9 @@
(ns app.main.ui.loader (ns app.main.ui.loader
(:require (:require
[rumext.alpha :as mf] [app.main.store :as st]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.store :as st])) [rumext.alpha :as mf]))
;; --- Component ;; --- Component

View file

@ -11,9 +11,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.store :as st]
[cuerdas.core :as str] [cuerdas.core :as str]
[okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
;; ------------------------------------------------ ;; ------------------------------------------------
@ -82,10 +80,10 @@
(and (neg? ss) (> ss se))) (and (neg? ss) (> ss se)))
(conj [ from-s (+ from-s ss) ]) (conj [ from-s (+ from-s ss) ])
(or (and (neg? se) (<= ss se))) (and (neg? se) (<= ss se))
(conj [ from-s (+ from-s se) ]) (conj [ from-s (+ from-s se) ])
(or (and (pos? es) (<= es ee))) (and (pos? es) (<= es ee))
(conj [ from-e (+ from-e es) ]) (conj [ from-e (+ from-e es) ])
(or (and (pos? ee) (neg? es)) (or (and (pos? ee) (neg? es))
@ -97,7 +95,7 @@
;; COMPONENTS ;; COMPONENTS
;; ------------------------------------------------ ;; ------------------------------------------------
(mf/defc size-display [{:keys [type selrect zoom]}] (mf/defc size-display [{:keys [selrect zoom]}]
(let [{:keys [x y width height]} selrect (let [{:keys [x y width height]} selrect
size-label (str/fmt "%s x %s" (mth/round width) (mth/round height)) size-label (str/fmt "%s x %s" (mth/round width) (mth/round height))
@ -127,7 +125,6 @@
(mf/defc distance-display-pill [{:keys [x y zoom distance bounds]}] (mf/defc distance-display-pill [{:keys [x y zoom distance bounds]}]
(let [distance-pill-width (/ distance-pill-width zoom) (let [distance-pill-width (/ distance-pill-width zoom)
distance-pill-height (/ distance-pill-height zoom) distance-pill-height (/ distance-pill-height zoom)
distance-line-stroke (/ distance-line-stroke zoom)
font-size (/ font-size zoom) font-size (/ font-size zoom)
text-padding (/ 3 zoom) text-padding (/ 3 zoom)
distance-border-radius (/ distance-border-radius zoom) distance-border-radius (/ distance-border-radius zoom)
@ -169,7 +166,7 @@
:font-size font-size}} :font-size font-size}}
distance]])) distance]]))
(mf/defc selection-rect [{:keys [frame selrect zoom]}] (mf/defc selection-rect [{:keys [selrect zoom]}]
(let [{:keys [x y width height]} selrect (let [{:keys [x y width height]} selrect
selection-rect-width (/ selection-rect-width zoom)] selection-rect-width (/ selection-rect-width zoom)]
[:g.selection-rect [:g.selection-rect
@ -181,7 +178,7 @@
:stroke hover-color :stroke hover-color
:stroke-width selection-rect-width}}]])) :stroke-width selection-rect-width}}]]))
(mf/defc distance-display [{:keys [type from to zoom frame bounds]}] (mf/defc distance-display [{:keys [from to zoom bounds]}]
(let [fixed-x (if (gsh/fully-contained? from to) (let [fixed-x (if (gsh/fully-contained? from to)
(+ (:x to) (/ (:width to) 2)) (+ (:x to) (/ (:width to) 2))
(+ (:x from) (/ (:width from) 2))) (+ (:x from) (/ (:width from) 2)))

View file

@ -6,7 +6,6 @@
(ns app.main.ui.messages (ns app.main.ui.messages
(:require (:require
[app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.refs :as refs] [app.main.refs :as refs]

View file

@ -7,7 +7,6 @@
(ns app.main.ui.modal (ns app.main.ui.modal
(:require (:require
[app.main.data.modal :as dm] [app.main.data.modal :as dm]
[app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.keyboard :as k] [app.util.keyboard :as k]
@ -19,8 +18,8 @@
(defn- on-esc-clicked (defn- on-esc-clicked
[event allow-click-outside] [event allow-click-outside]
(when (and (k/esc? event) (not allow-click-outside)) (when (and (k/esc? event) (not allow-click-outside))
(do (dom/stop-propagation event) (dom/stop-propagation event)
(st/emit! (dm/hide))))) (st/emit! (dm/hide))))
(defn- on-pop-state (defn- on-pop-state
[event] [event]
@ -29,16 +28,6 @@
(st/emit! (dm/hide)) (st/emit! (dm/hide))
(.forward js/history)) (.forward js/history))
(defn- on-parent-clicked
[event parent-ref]
(let [parent (mf/ref-val parent-ref)
current (dom/get-target event)]
(when (and (dom/equals? (.-firstElementChild ^js parent) current)
(= (.-className ^js current) "modal-overlay"))
(dom/stop-propagation event)
(dom/prevent-default event)
(st/emit! (dm/hide)))))
(defn- on-click-outside (defn- on-click-outside
[event wrapper-ref type allow-click-outside] [event wrapper-ref type allow-click-outside]
(let [wrapper (mf/ref-val wrapper-ref) (let [wrapper (mf/ref-val wrapper-ref)

View file

@ -6,18 +6,18 @@
(ns app.main.ui.onboarding (ns app.main.ui.onboarding
(:require (:require
[app.config :as cf]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cf]
[app.main.data.dashboard :as dd] [app.main.data.dashboard :as dd]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.users :as du] [app.main.data.users :as du]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.forms :as fm :refer [input submit-button form]] [app.main.ui.components.forms :as fm]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.object :as obj]
[app.util.router :as rt] [app.util.router :as rt]
[app.util.timers :as tm] [app.util.timers :as tm]
[app.util.object :as obj]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
@ -186,24 +186,24 @@
(mf/defc onboarding-team-modal (mf/defc onboarding-team-modal
{::mf/register modal/components {::mf/register modal/components
::mf/register-as :onboarding-team} ::mf/register-as :onboarding-team}
[props] []
(let [close (mf/use-fn (st/emitf (modal/hide))) (let [close (mf/use-fn (st/emitf (modal/hide)))
form (fm/use-form :spec ::team-form form (fm/use-form :spec ::team-form
:initial {}) :initial {})
on-success on-success
(mf/use-callback (mf/use-callback
(fn [form response] (fn [_form response]
(st/emit! (modal/hide) (st/emit! (modal/hide)
(rt/nav :dashboard-projects {:team-id (:id response)})))) (rt/nav :dashboard-projects {:team-id (:id response)}))))
on-error on-error
(mf/use-callback (mf/use-callback
(fn [form response] (fn [_form _response]
(st/emit! (dm/error "Error on creating team.")))) (st/emit! (dm/error "Error on creating team."))))
on-submit on-submit
(mf/use-callback (mf/use-callback
(fn [form event] (fn [form _event]
(let [mdata {:on-success (partial on-success form) (let [mdata {:on-success (partial on-success form)
:on-error (partial on-error form)} :on-error (partial on-error form)}
params {:name (get-in @form [:clean-data :name])}] params {:name (get-in @form [:clean-data :name])}]

View file

@ -9,7 +9,6 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
@ -20,7 +19,6 @@
[app.main.ui.shapes.filters :as filters] [app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.shape :refer [shape-container]] [app.main.ui.shapes.shape :refer [shape-container]]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s]
[cuerdas.core :as str] [cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
@ -44,8 +42,6 @@
objects (reduce updt-fn objects mod-ids) objects (reduce updt-fn objects mod-ids)
object (get objects object-id) object (get objects object-id)
{:keys [width height]} (gsh/points->selrect (:points object))
;; We need to get the shadows/blurs paddings to create the viewbox properly ;; We need to get the shadows/blurs paddings to create the viewbox properly
{:keys [x y width height]} (filters/get-filters-bounds object) {:keys [x y width height]} (filters/get-filters-bounds object)
@ -115,7 +111,7 @@
(repo/query! :font-variants {:file-id file-id}) (repo/query! :font-variants {:file-id file-id})
(repo/query! :file {:id file-id})) (repo/query! :file {:id file-id}))
(rx/subs (rx/subs
(fn [[fonts {:keys [data]} :as kaka]] (fn [[fonts {:keys [data]}]]
(when (seq fonts) (when (seq fonts)
(st/emit! (df/fonts-fetched fonts))) (st/emit! (df/fonts-fetched fonts)))
(let [objs (get-in data [:pages-index page-id :objects]) (let [objs (get-in data [:pages-index page-id :objects])

View file

@ -7,14 +7,13 @@
(ns app.main.ui.settings (ns app.main.ui.settings
(:require (:require
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.ui.settings.change-email]
[app.main.ui.settings.options :refer [options-page]] [app.main.ui.settings.delete-account]
[app.main.ui.settings.feedback :refer [feedback-page]] [app.main.ui.settings.feedback :refer [feedback-page]]
[app.main.ui.settings.options :refer [options-page]]
[app.main.ui.settings.password :refer [password-page]] [app.main.ui.settings.password :refer [password-page]]
[app.main.ui.settings.profile :refer [profile-page]] [app.main.ui.settings.profile :refer [profile-page]]
[app.main.ui.settings.sidebar :refer [sidebar]] [app.main.ui.settings.sidebar :refer [sidebar]]
[app.main.ui.settings.change-email]
[app.main.ui.settings.delete-account]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))

View file

@ -15,10 +15,9 @@
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.messages :as msgs] [app.main.ui.messages :as msgs]
[app.util.i18n :as i18n :refer [tr t]] [app.util.i18n :as i18n :refer [tr]]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(s/def ::email-1 ::us/email) (s/def ::email-1 ::us/email)
@ -63,7 +62,7 @@
(modal/hide))))) (modal/hide)))))
(defn- on-submit (defn- on-submit
[form event] [form _event]
(let [params {:email (get-in @form [:clean-data :email-1])} (let [params {:email (get-in @form [:clean-data :email-1])}
mdata {:on-error (partial on-error form) mdata {:on-error (partial on-error form)
:on-success (partial on-success form)}] :on-success (partial on-success form)}]
@ -73,8 +72,7 @@
{::mf/register modal/components {::mf/register modal/components
::mf/register-as :change-email} ::mf/register-as :change-email}
[] []
(let [locale (mf/deref i18n/locale) (let [profile (mf/deref refs/profile)
profile (mf/deref refs/profile)
form (fm/use-form :spec ::email-change-form form (fm/use-form :spec ::email-change-form
:validators [email-equality] :validators [email-equality]
:initial profile) :initial profile)
@ -88,30 +86,30 @@
[:div.modal-header [:div.modal-header
[:div.modal-header-title [:div.modal-header-title
[:h2 (t locale "modals.change-email.title")]] [:h2 (tr "modals.change-email.title")]]
[:div.modal-close-button [:div.modal-close-button
{:on-click on-close} i/close]] {:on-click on-close} i/close]]
[:div.modal-content [:div.modal-content
[:& msgs/inline-banner [:& msgs/inline-banner
{:type :info {:type :info
:content (t locale "modals.change-email.info" (:email profile))}] :content (tr "modals.change-email.info" (:email profile))}]
[:div.fields-row [:div.fields-row
[:& fm/input {:type "text" [:& fm/input {:type "text"
:name :email-1 :name :email-1
:label (t locale "modals.change-email.new-email") :label (tr "modals.change-email.new-email")
:trim true}]] :trim true}]]
[:div.fields-row [:div.fields-row
[:& fm/input {:type "text" [:& fm/input {:type "text"
:name :email-2 :name :email-2
:label (t locale "modals.change-email.confirm-email") :label (tr "modals.change-email.confirm-email")
:trim true}]]] :trim true}]]]
[:div.modal-footer [:div.modal-footer
[:div.action-buttons [:div.action-buttons
[:& fm/submit-button [:& fm/submit-button
{:label (t locale "modals.change-email.submit")}]]]]]])) {:label (tr "modals.change-email.submit")}]]]]]]))

View file

@ -13,9 +13,7 @@
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.messages :as msgs] [app.main.ui.messages :as msgs]
[app.util.i18n :as i18n :refer [tr]] [app.util.i18n :as i18n :refer [tr]]
[app.util.router :as rt]
[beicon.core :as rx] [beicon.core :as rx]
[cljs.spec.alpha :as s]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(defn on-error (defn on-error
@ -28,7 +26,7 @@
(mf/defc delete-account-modal (mf/defc delete-account-modal
{::mf/register modal/components {::mf/register modal/components
::mf/register-as :delete-account} ::mf/register-as :delete-account}
[props] []
(let [on-close (let [on-close
(mf/use-callback (st/emitf (modal/hide))) (mf/use-callback (st/emitf (modal/hide)))

View file

@ -13,7 +13,6 @@
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]] [app.util.i18n :as i18n :refer [t tr]]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -26,11 +25,11 @@
(s/keys :opt-un [::lang ::theme])) (s/keys :opt-un [::lang ::theme]))
(defn- on-success (defn- on-success
[form] [_]
(st/emit! (dm/success (tr "notifications.profile-saved")))) (st/emit! (dm/success (tr "notifications.profile-saved"))))
(defn- on-submit (defn- on-submit
[form event] [form _event]
(let [data (:clean-data @form) (let [data (:clean-data @form)
data (cond-> data data (cond-> data
(empty? (:lang data)) (empty? (:lang data))

View file

@ -11,7 +11,6 @@
[app.main.data.users :as udu] [app.main.data.users :as udu]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t tr]] [app.util.i18n :as i18n :refer [t tr]]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
@ -29,7 +28,7 @@
(st/emit! (dm/error msg))))) (st/emit! (dm/error msg)))))
(defn- on-success (defn- on-success
[form] [_]
(let [msg (tr "dashboard.notifications.password-saved")] (let [msg (tr "dashboard.notifications.password-saved")]
(st/emit! (dm/success msg)))) (st/emit! (dm/success msg))))

View file

@ -6,8 +6,8 @@
(ns app.main.ui.settings.profile (ns app.main.ui.settings.profile
(:require (:require
[app.config :as cfg]
[app.common.spec :as us] [app.common.spec :as us]
[app.config :as cfg]
[app.main.data.messages :as dm] [app.main.data.messages :as dm]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.users :as du] [app.main.data.users :as du]
@ -16,13 +16,10 @@
[app.main.ui.components.file-uploader :refer [file-uploader]] [app.main.ui.components.file-uploader :refer [file-uploader]]
[app.main.ui.components.forms :as fm] [app.main.ui.components.forms :as fm]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.main.ui.messages :as msgs]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr t]] [app.util.i18n :as i18n :refer [tr t]]
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[cuerdas.core :as str] [rumext.alpha :as mf]))
[rumext.alpha :as mf]
[app.config :as cfg]))
(s/def ::fullname ::us/not-empty-string) (s/def ::fullname ::us/not-empty-string)
(s/def ::email ::us/email) (s/def ::email ::us/email)
@ -31,11 +28,11 @@
(s/keys :req-un [::fullname ::email])) (s/keys :req-un [::fullname ::email]))
(defn- on-success (defn- on-success
[form] [_]
(st/emit! (dm/success (tr "notifications.profile-saved")))) (st/emit! (dm/success (tr "notifications.profile-saved"))))
(defn- on-submit (defn- on-submit
[form event] [form _event]
(let [data (:clean-data @form) (let [data (:clean-data @form)
mdata {:on-success (partial on-success form)}] mdata {:on-success (partial on-success form)}]
(st/emit! (du/update-profile (with-meta data mdata))))) (st/emit! (du/update-profile (with-meta data mdata)))))

View file

@ -20,7 +20,7 @@
[app.util.http :as http] [app.util.http :as http]
[app.util.i18n :as i18n :refer [tr t]])) [app.util.i18n :as i18n :refer [tr t]]))
(defn- request-export (defn request-export
[shape exports] [shape exports]
(rp/query! :export (rp/query! :export
{:page-id (:page-id shape) {:page-id (:page-id shape)