0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-09 14:21:42 -05:00

❇️ Fix linter warnings

This commit is contained in:
alonso.torres 2021-06-18 15:29:07 +02:00
parent fbf1c10077
commit 234a698538
10 changed files with 55 additions and 115 deletions

View file

@ -17,14 +17,7 @@
{:exclude-files {:exclude-files
["data_readers.clj" ["data_readers.clj"
"app/util/perf.cljs" "app/util/perf.cljs"
"app/common/exceptions.cljc" "app/common/exceptions.cljc"]}
"app/util/import/.*"
"app/worker/export.cljs"
"app/worker/import.cljs"
"app/libs/.*"
"app/main/data/workspace/path/selection.cljs"
"app/main/data/workspace/transforms.cljs"
]}
:linters :linters
{:unsorted-required-namespaces {:unsorted-required-namespaces

View file

@ -25,59 +25,59 @@
(deftype File [^:mutable file] (deftype File [^:mutable file]
Object Object
(addPage [self name] (addPage [_ name]
(set! file (fb/add-page file {:name name})) (set! file (fb/add-page file {:name name}))
(str (:current-page-id file))) (str (:current-page-id file)))
(addPage [self name options] (addPage [_ name options]
(set! file (fb/add-page file {:name name :options options})) (set! file (fb/add-page file {:name name :options options}))
(str (:current-page-id file))) (str (:current-page-id file)))
(closePage [self] (closePage [_]
(set! file (fb/close-page file))) (set! file (fb/close-page file)))
(addArtboard [self data] (addArtboard [_ data]
(set! file (fb/add-artboard file (parse-data data))) (set! file (fb/add-artboard file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(closeArtboard [self data] (closeArtboard [_]
(set! file (fb/close-artboard file))) (set! file (fb/close-artboard file)))
(addGroup [self data] (addGroup [_ data]
(set! file (fb/add-group file (parse-data data))) (set! file (fb/add-group file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(closeGroup [self] (closeGroup [_]
(set! file (fb/close-group file))) (set! file (fb/close-group file)))
(createRect [self data] (createRect [_ data]
(set! file (fb/create-rect file (parse-data data))) (set! file (fb/create-rect file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(createCircle [self data] (createCircle [_ data]
(set! file (fb/create-circle file (parse-data data))) (set! file (fb/create-circle file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(createPath [self data] (createPath [_ data]
(set! file (fb/create-path file (parse-data data))) (set! file (fb/create-path file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(createText [self data] (createText [_ data]
(set! file (fb/create-text file (parse-data data))) (set! file (fb/create-text file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(createImage [self data] (createImage [_ data]
(set! file (fb/create-image file (parse-data data))) (set! file (fb/create-image file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(createSVG [self data] (createSVG [_ data]
(set! file (fb/create-svg-raw file (parse-data data))) (set! file (fb/create-svg-raw file (parse-data data)))
(str (:last-id file))) (str (:last-id file)))
(closeSVG [self] (closeSVG [_]
(set! file (fb/close-svg-raw file))) (set! file (fb/close-svg-raw file)))
(asMap [self] (asMap [_]
(clj->js file))) (clj->js file)))
(defn create-file-export [^string name] (defn create-file-export [^string name]

View file

@ -141,9 +141,9 @@
selected? (contains? selected-points position)] selected? (contains? selected-points position)]
(streams/drag-stream (streams/drag-stream
(rx/of (rx/of
(when-not selected? (selection/select-node position shift? "drag")) (when-not selected? (selection/select-node position shift?))
(drag-selected-points @ms/mouse-position)) (drag-selected-points @ms/mouse-position))
(rx/of (selection/select-node position shift? "click"))))))) (rx/of (selection/select-node position shift?)))))))
(defn drag-selected-points (defn drag-selected-points
[start-position] [start-position]

View file

@ -60,7 +60,7 @@
(some? id) (some? id)
(assoc-in [:workspace-local :edit-path id :selected-points] positions)))))) (assoc-in [:workspace-local :edit-path id :selected-points] positions))))))
(defn select-node [position shift? kk] (defn select-node [position shift?]
(ptk/reify ::select-node (ptk/reify ::select-node
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
@ -79,38 +79,6 @@
(some? id) (some? id)
(assoc-in [:workspace-local :edit-path id :selected-points] selected-points)))))) (assoc-in [:workspace-local :edit-path id :selected-points] selected-points))))))
(defn deselect-node [position shift?]
(ptk/reify ::deselect-node
ptk/UpdateEvent
(update [_ state]
(let [id (get-in state [:workspace-local :edition])]
(-> state
(update-in [:workspace-local :edit-path id :selected-points] (fnil disj #{}) position))))))
(defn add-to-selection-handler [index type]
(ptk/reify ::add-to-selection-handler
ptk/UpdateEvent
(update [_ state]
state)))
(defn add-to-selection-node [index]
(ptk/reify ::add-to-selection-node
ptk/UpdateEvent
(update [_ state]
state)))
(defn remove-from-selection-handler [index]
(ptk/reify ::remove-from-selection-handler
ptk/UpdateEvent
(update [_ state]
state)))
(defn remove-from-selection-node [index]
(ptk/reify ::remove-from-selection-handler
ptk/UpdateEvent
(update [_ state]
state)))
(defn deselect-all [] (defn deselect-all []
(ptk/reify ::deselect-all (ptk/reify ::deselect-all
ptk/UpdateEvent ptk/UpdateEvent
@ -140,7 +108,7 @@
(ptk/reify ::handle-selection (ptk/reify ::handle-selection
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ _ stream]
(let [stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event))) (let [stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event)))
stoper (->> stream (rx/filter stop?)) stoper (->> stream (rx/filter stop?))
from-p @ms/mouse-position] from-p @ms/mouse-position]

View file

@ -98,8 +98,8 @@
;; -- RESIZE ;; -- RESIZE
(defn start-resize (defn start-resize
[handler initial ids shape] [handler ids shape]
(letfn [(resize [shape initial resizing-shapes layout [point lock? point-snap]] (letfn [(resize [shape initial layout [point lock? point-snap]]
(let [{:keys [width height]} (:selrect shape) (let [{:keys [width height]} (:selrect shape)
{:keys [rotation]} shape {:keys [rotation]} shape
rotation (or rotation 0) rotation (or rotation 0)
@ -181,7 +181,7 @@
(rx/switch-map (fn [[point :as current]] (rx/switch-map (fn [[point :as current]]
(->> (snap/closest-snap-point page-id resizing-shapes layout zoom point) (->> (snap/closest-snap-point page-id resizing-shapes layout zoom point)
(rx/map #(conj current %))))) (rx/map #(conj current %)))))
(rx/mapcat (partial resize shape initial-position resizing-shapes layout)) (rx/mapcat (partial resize shape initial-position layout))
(rx/take-until stoper)) (rx/take-until stoper))
(rx/of (apply-modifiers ids) (rx/of (apply-modifiers ids)
(finish-transform)))))))) (finish-transform))))))))
@ -196,7 +196,7 @@
(assoc-in [:workspace-local :transform] :rotate))) (assoc-in [:workspace-local :transform] :rotate)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ stream]
(let [stoper (rx/filter ms/mouse-up? stream) (let [stoper (rx/filter ms/mouse-up? stream)
group (gsh/selection-rect shapes) group (gsh/selection-rect shapes)
group-center (gsh/center-selrect group) group-center (gsh/center-selrect group)
@ -235,7 +235,7 @@
[] []
(ptk/reify ::start-move-selected (ptk/reify ::start-move-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [initial (deref ms/mouse-position) (let [initial (deref ms/mouse-position)
selected (wsh/lookup-selected state {:omit-blocked? true}) selected (wsh/lookup-selected state {:omit-blocked? true})
stopper (rx/filter ms/mouse-up? stream)] stopper (rx/filter ms/mouse-up? stream)]
@ -259,7 +259,7 @@
(defn start-move-duplicate [from-position] (defn start-move-duplicate [from-position]
(ptk/reify ::start-move-selected (ptk/reify ::start-move-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ _ stream]
(->> stream (->> stream
(rx/filter (ptk/type? ::dws/duplicate-selected)) (rx/filter (ptk/type? ::dws/duplicate-selected))
(rx/first) (rx/first)
@ -268,7 +268,7 @@
(defn calculate-frame-for-move [ids] (defn calculate-frame-for-move [ids]
(ptk/reify ::calculate-frame-for-move (ptk/reify ::calculate-frame-for-move
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [it state _]
(let [position @ms/mouse-position (let [position @ms/mouse-position
page-id (:current-page-id state) page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -313,7 +313,7 @@
(assoc-in [:workspace-local :transform] :move))) (assoc-in [:workspace-local :transform] :move)))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state {:omit-blocked? true}) selected (wsh/lookup-selected state {:omit-blocked? true})
@ -349,20 +349,6 @@
(calculate-frame-for-move ids) (calculate-frame-for-move ids)
(finish-transform))))))))) (finish-transform)))))))))
(defn- get-displacement-with-grid
"Retrieve the correct displacement delta point for the
provided direction speed and distances thresholds."
[shape direction options]
(let [grid-x (:grid-x options 10)
grid-y (:grid-y options 10)
x-mod (mod (:x shape) grid-x)
y-mod (mod (:y shape) grid-y)]
(case direction
:up (gpt/point 0 (- (if (zero? y-mod) grid-y y-mod)))
:down (gpt/point 0 (- grid-y y-mod))
:left (gpt/point (- (if (zero? x-mod) grid-x x-mod)) 0)
:right (gpt/point (- grid-x x-mod) 0))))
(defn- get-displacement (defn- get-displacement
"Retrieve the correct displacement delta point for the "Retrieve the correct displacement delta point for the
provided direction speed and distances thresholds." provided direction speed and distances thresholds."
@ -394,7 +380,7 @@
state)) state))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state stream]
(if (= same-event (get-in state [:workspace-local :current-move-selected])) (if (= same-event (get-in state [:workspace-local :current-move-selected]))
(let [selected (wsh/lookup-selected state {:omit-blocked? true}) (let [selected (wsh/lookup-selected state {:omit-blocked? true})
move-events (->> stream move-events (->> stream
@ -539,7 +525,7 @@
(defn increase-rotation [ids rotation] (defn increase-rotation [ids rotation]
(ptk/reify ::increase-rotation (ptk/reify ::increase-rotation
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
@ -559,7 +545,7 @@
(us/verify (s/coll-of uuid?) ids) (us/verify (s/coll-of uuid?) ids)
(ptk/reify ::apply-modifiers (ptk/reify ::apply-modifiers
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
children-ids (->> ids (mapcat #(cp/get-children % objects))) children-ids (->> ids (mapcat #(cp/get-children % objects)))
ids-with-children (d/concat [] children-ids ids) ids-with-children (d/concat [] children-ids ids)
@ -610,11 +596,6 @@
(update [_ state] (update [_ state]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
update-children
(fn [objects ids modifiers]
(reduce #(assoc-in %1 [%2 :modifiers] modifiers) objects ids))
;; For each shape updates the modifiers given as arguments ;; For each shape updates the modifiers given as arguments
update-shape update-shape
@ -629,7 +610,7 @@
#(reduce update-shape % ids)))) #(reduce update-shape % ids))))
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
ids (d/concat [] ids (mapcat #(cp/get-children % objects) ids))] ids (d/concat [] ids (mapcat #(cp/get-children % objects) ids))]
@ -638,7 +619,7 @@
(defn flip-horizontal-selected [] (defn flip-horizontal-selected []
(ptk/reify ::flip-horizontal-selected (ptk/reify ::flip-horizontal-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state {:omit-blocked? true}) selected (wsh/lookup-selected state {:omit-blocked? true})
shapes (map #(get objects %) selected) shapes (map #(get objects %) selected)
@ -654,7 +635,7 @@
(defn flip-vertical-selected [] (defn flip-vertical-selected []
(ptk/reify ::flip-vertical-selected (ptk/reify ::flip-vertical-selected
ptk/WatchEvent ptk/WatchEvent
(watch [it state stream] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state {:omit-blocked? true}) selected (wsh/lookup-selected state {:omit-blocked? true})
shapes (map #(get objects %) selected) shapes (map #(get objects %) selected)
@ -687,6 +668,6 @@
[] []
(ptk/reify ::selected-to-path (ptk/reify ::selected-to-path
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state _]
(let [ids (wsh/lookup-selected state {:omit-blocked? true})] (let [ids (wsh/lookup-selected state {:omit-blocked? true})]
(rx/of (dch/update-shapes ids ups/convert-to-path)))))) (rx/of (dch/update-shapes ids ups/convert-to-path))))))

View file

@ -191,8 +191,7 @@
(mf/defc export-data (mf/defc export-data
[{:keys [shape]}] [{:keys [shape]}]
(let [props (-> (obj/new) (add-data shape)) (let [props (-> (obj/new) (add-data shape))]
frame? (= (:type shape) :frame)]
[:> "penpot:shape" props [:> "penpot:shape" props
[:& export-shadow-data shape] [:& export-shadow-data shape]
[:& export-blur-data shape] [:& export-blur-data shape]

View file

@ -286,9 +286,9 @@
shape-center (geom/center-shape shape) shape-center (geom/center-shape shape)
on-resize (fn [current-position initial-position event] on-resize (fn [current-position _initial-position event]
(dom/stop-propagation event) (dom/stop-propagation event)
(st/emit! (dw/start-resize current-position initial-position selected shape))) (st/emit! (dw/start-resize current-position selected shape)))
on-rotate #(do (dom/stop-propagation %) on-rotate #(do (dom/stop-propagation %)
(st/emit! (dw/start-rotate shapes)))] (st/emit! (dw/start-rotate shapes)))]
@ -311,9 +311,9 @@
shape (geom/transform-shape shape {:round-coords? false}) shape (geom/transform-shape shape {:round-coords? false})
shape' (if (debug? :simple-selection) (geom/setup {:type :rect} (geom/selection-rect [shape])) shape) shape' (if (debug? :simple-selection) (geom/setup {:type :rect} (geom/selection-rect [shape])) shape)
on-resize (fn [current-position initial-position event] on-resize (fn [current-position _initial-position event]
(dom/stop-propagation event) (dom/stop-propagation event)
(st/emit! (dw/start-resize current-position initial-position #{shape-id} shape'))) (st/emit! (dw/start-resize current-position #{shape-id} shape')))
on-rotate on-rotate
#(do (dom/stop-propagation %) #(do (dom/stop-propagation %)

View file

@ -126,7 +126,7 @@
(defn without-penpot-prefix (defn without-penpot-prefix
[m] [m]
(let [no-penpot-prefix? (let [no-penpot-prefix?
(fn [[k v]] (fn [[k _]]
(not (str/starts-with? (d/name k) "penpot:")))] (not (str/starts-with? (d/name k) "penpot:")))]
(into {} (filter no-penpot-prefix?) m))) (into {} (filter no-penpot-prefix?) m)))
@ -191,11 +191,11 @@
[props svg-data] [props svg-data]
(let [values (->> (select-keys svg-data [:cx :cy :rx :ry]) (let [values (->> (select-keys svg-data [:cx :cy :rx :ry])
(d/mapm (fn [_ val] (d/parse-double val))))] (d/mapm (fn [_ val] (d/parse-double val))))]
(-> props
{:x (- (:cx values) (:rx values)) (assoc :x (- (:cx values) (:rx values))
:y (- (:cy values) (:ry values)) :y (- (:cy values) (:ry values))
:width (* (:rx values) 2) :width (* (:rx values) 2)
:height (* (:ry values) 2)})) :height (* (:ry values) 2)))))
(defn parse-path (defn parse-path
[props center svg-data] [props center svg-data]
@ -459,7 +459,7 @@
[props node] [props node]
(let [shadows (extract-from-data node :penpot:shadow parse-shadow)] (let [shadows (extract-from-data node :penpot:shadow parse-shadow)]
(cond-> props (cond-> props
(not (empty? shadows)) (d/not-empty? shadows)
(assoc :shadow shadows)))) (assoc :shadow shadows))))
(defn add-blur (defn add-blur
@ -473,7 +473,7 @@
[props node] [props node]
(let [exports (extract-from-data node :penpot:export parse-export)] (let [exports (extract-from-data node :penpot:export parse-export)]
(cond-> props (cond-> props
(not (empty? exports)) (d/not-empty? exports)
(assoc :exports exports)))) (assoc :exports exports))))
(defn add-layer-options (defn add-layer-options
@ -507,7 +507,7 @@
(reduce assoc-key {})))) (reduce assoc-key {}))))
(defn get-svg-defs (defn get-svg-defs
[node svg-defs] [node]
(let [svg-import (get-data node :penpot:svg-import)] (let [svg-import (get-data node :penpot:svg-import)]
(->> svg-import (->> svg-import
@ -545,7 +545,7 @@
(some? svg-defs) (some? svg-defs)
(assoc :svg-defs (get-svg-defs node svg-defs)))) (assoc :svg-defs (get-svg-defs node))))
props))) props)))
@ -571,7 +571,7 @@
(defn add-frame-data [props node] (defn add-frame-data [props node]
(let [grids (parse-grids node)] (let [grids (parse-grids node)]
(cond-> props (cond-> props
(not (empty? grids)) (d/not-empty? grids)
(assoc :grids grids)))) (assoc :grids grids))))
(defn has-image? (defn has-image?
@ -641,12 +641,12 @@
background (:background style) background (:background style)
grids (->> (parse-grids node) grids (->> (parse-grids node)
(group-by :type) (group-by :type)
(d/mapm (fn [k v] (-> v first :params))))] (d/mapm (fn [_ v] (-> v first :params))))]
(cond-> {} (cond-> {}
(some? background) (some? background)
(assoc-in [:options :background] background) (assoc-in [:options :background] background)
(not (empty? grids)) (d/not-empty? grids)
(assoc-in [:options :saved-grids] grids)))) (assoc-in [:options :saved-grids] grids))))
(defn parse-interactions (defn parse-interactions

View file

@ -182,7 +182,7 @@
(rx/map #(vector (get files file-id) %))))))))) (rx/map #(vector (get files file-id) %)))))))))
(defmethod impl/handler :export-file (defmethod impl/handler :export-file
[{:keys [team-id project-id files] :as message}] [{:keys [team-id files] :as message}]
(->> (rx/from files) (->> (rx/from files)
(rx/mapcat #(export-file team-id %)) (rx/mapcat #(export-file team-id %))

View file

@ -17,7 +17,6 @@
[app.util.zip :as uz] [app.util.zip :as uz]
[app.worker.impl :as impl] [app.worker.impl :as impl]
[beicon.core :as rx] [beicon.core :as rx]
[cuerdas.core :as str]
[tubax.core :as tubax])) [tubax.core :as tubax]))
;; Upload changes batches size ;; Upload changes batches size
@ -111,7 +110,7 @@
(some? (:last-id file)) (some? (:last-id file))
(assoc-in [:id-mapping old-id] (:last-id file)) (assoc-in [:id-mapping old-id] (:last-id file))
(not (empty? interactions)) (d/not-empty? interactions)
(assoc-in [:interactions old-id] interactions)))))) (assoc-in [:interactions old-id] interactions))))))
(defn post-process-file (defn post-process-file